Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PhoneGap/Cordova BlackBerry FileSystem.root是否始终返回SD卡?_Cordova_Blackberry_File Io_Sd Card - Fatal编程技术网

PhoneGap/Cordova BlackBerry FileSystem.root是否始终返回SD卡?

PhoneGap/Cordova BlackBerry FileSystem.root是否始终返回SD卡?,cordova,blackberry,file-io,sd-card,Cordova,Blackberry,File Io,Sd Card,我在BlackBerry上加载了两个应用程序,一个是本地应用程序,另一个是基于PhoneGap/Cordova的应用程序 这两个应用程序共享一个设置文件:file:///store/home/user/myfile.txt 要通过Cordova访问此文件,请拨打: fileSystem.root.getFile(“home/user/myfile.txt”,null,gotFileEntry,fail) 但是,在某些设备上,fileSystem.root返回SD卡目录,而不是存储文件的内部内存,

我在BlackBerry上加载了两个应用程序,一个是本地应用程序,另一个是基于PhoneGap/Cordova的应用程序

这两个应用程序共享一个设置文件:
file:///store/home/user/myfile.txt

要通过Cordova访问此文件,请拨打:

fileSystem.root.getFile(“home/user/myfile.txt”,null,gotFileEntry,fail)

但是,在某些设备上,
fileSystem.root
返回SD卡目录,而不是存储文件的内部内存,因此出现
FileNotFound
错误

我尝试调用
fileSystem.root.getParent(gotParent,fail),希望获取文件系统的根,然后从内部内存获取文件,如下所示:

parentDir.getFile(“store/home/user/myfile.txt”,null,gotFileEntry,fail)

但这也不起作用,我仍然收到一个文件未找到错误


如何每次使用PhoneGap/Cordova获取内部内存的根目录?

您使用哪种版本的Cordova?
自BlackBerry WebWorks(操作系统5.0及更高版本)以来,Cordova一直受到支持

您只想读取(和写入)该文件的假设正确吗?
如果是这样,您可以尝试使用和

文件阅读器

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);
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);
文件编写器

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);
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);
否则尝试一下该代码段(代码来自一个旧项目,但在当时仍然有效)


//等待PhoneGap加载
//
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//PhoneGap已经准备好了
//
函数ondevicerady(){
requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail);
}
函数gotFS(文件系统){
var path=“readme.txt”;
getFile(路径,{create:true,exclusive:false},gotFileEntry,fail);
}
函数gotFileEntry(fileEntry){
createWriter(gotFileWriter,失败);
}
函数gotFileWriter(writer){
writer.onwrite=函数(evt){
console.log(“写入成功”);
};
writer.write(“一些示例文本”);

我希望我能帮助你,祝你好运 F481