File 写入文件phonegap
我在互联网上看到了很多关于用phonegap写入文件的问题,但没有一个对我有效。我尝试过官方的phonegap文档,但它总是返回File 写入文件phonegap,file,cordova,File,Cordova,我在互联网上看到了很多关于用phonegap写入文件的问题,但没有一个对我有效。我尝试过官方的phonegap文档,但它总是返回错误。代码1。我不知道这到底意味着什么 我尝试了以下解决方案 // Wait for PhoneGap to load document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap is ready function onDeviceReady() { window.r
错误。代码1。
我不知道这到底意味着什么
我尝试了以下解决方案
// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function fail(){
console.log('fail');
}
function gotFS(fileSystem) {
var path = "test.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");
$.ajax({
url:'test.txt',
success:function(msg){
console.log('message: '+msg)
}
})
}
但是当执行函数gotFileWriter()
时,控制台会记录:write success
,但是我的ajax返回一个无效文档
我使用的是2.4.0版本,当我尝试文档2.4.0时,我有以下日志:
代码写入文件系统中的文件,而您发出的ajax请求位于www文件夹中。由于www文件夹中不存在test.txt文件,因此会出现该错误 请使用文件读取器读取文件。
getFile(“test.txt”,null,gotFileEntry,fail) 你是对的,每次都和医生在一起,thanks@ant您创建的文件在文件系统中的确切位置?我不能传递文件的确切路径:///路径吗?