PhoneGap的/科尔多瓦黑莓FileSystem.root总是返回SD卡? [英] PhoneGap/Cordova BlackBerry FileSystem.root always returns SD card?
问题描述
我有两个应用程序,我装上一个黑莓手机,一种是本地应用程序,另一种是基于PhoneGap的/科尔多瓦的应用程序。
I have two applications I'm loading on a BlackBerry, one is a native application, the other is a PhoneGap / Cordova based application.
这两个应用程序共享的设置文件:文件:///store/home/user/myfile.txt
These two applications share a settings file: file:///store/home/user/myfile.txt
要通过科尔多瓦访问该文件,我呼吁:
To access this file via Cordova, I call:
fileSystem.root.getFile(家用/用户/ myfile.txt的,空,gotFileEntry,失败);
然而,在某些设备上 fileSystem.root
返回SD卡目录,而不是内部存储器所在的文件存储,所以我得到一个 FileNotFound
错误。
However, on some devices fileSystem.root
returns the SDCard directory, not the internal memory where the file is stored, so I get a FileNotFound
error.
我已经打过电话 fileSystem.root.getParent(gotParent,失败);
,希望能得到文件系统的根目录,然后得到像内部存储器中的文件所以:
I've tried calling fileSystem.root.getParent(gotParent, fail);
, hoping to get the root of the filesystem, then get the file from internal memory like so:
parentDir.getFile(存储/ home / user中/ myfile.txt的,空,gotFileEntry,失败);
但是,这也不行,我仍然收到找不到错误的文件。
But that doesn't work either, I still receive a file not found error.
我如何获得内部存储器中的每一次的根目录中,使用的PhoneGap /科尔多瓦?
How can I get the root directory of the internal memory every time, using PhoneGap/Cordova?
推荐答案
你用什么版本的科尔多瓦?结果
科尔多瓦因为黑莓WebWorks的(OS文件-API 支持5.0和更高)。
What version of Cordova do you use?
Cordova File-API is supported since BlackBerry WebWorks (OS 5.0 and higher).
我是正确的,你只需要读(写),该文件假设?结果
如果是的话,你可以尝试使用科尔多瓦文件阅读器和科尔多瓦文件的作家。
Am I right in the assumption that you only want to read (and write) that file?
If so you can try to use the Cordova File-Reader and the Cordova File-Writer.
的FileReader
function win(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("read success");
console.log(evt.target.result);
};
reader.readAsText(file);
};
var fail = function(evt) {
console.log(error.code);
};
entry.file(win, fail);
的FileWriter
function win(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.seek(writer.length);
writer.write("appended text");
};
var fail = function(evt) {
console.log(error.code);
};
entry.createWriter(win, fail);
,否则把那片段一试(code是一个老项目,但当时工作)
Otherwise give that snippet a try (code is of an old project but worked at that time)
<script type="text/javascript" charset="utf-8" src="css-js/phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
var path = "readme.txt";
fileSystem.root.getFile(path, {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write("some sample text");
我希望我可以帮你,最好的问候
F481
I hope I could help you, best regards F481
这篇关于PhoneGap的/科尔多瓦黑莓FileSystem.root总是返回SD卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!