2012-04-15 82 views
0

我一直在试图让一个应用程序写一些文本到phonegap/cordova 1.6.0 for windows phone下的文件,使用phonegap/cordova中的例子API,但没有任何运气。Phonegap /科尔多瓦1.6.0 WP7写入到WWW文件夹中的文件

该文件是一个在'www'文件夹中手动创建的.txt文件,通过使用console.log和.onerror和.onwriteend事件函数,我可以看到作者认为完成了任务成功写入文件,但文件的内容完全不会改变。

有没有人知道这个原因?

下面是来自API的例子(在那里你看到的 “readme.txt” 我用 “/app/www/file.txt”):

function onDeviceReady() { 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); 
} 

function gotFS(fileSystem) { 
    fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail); 
} 

function gotFileEntry(fileEntry) { 
    fileEntry.createWriter(gotFileWriter, fail); 
} 

function gotFileWriter(writer) { 
    writer.onwriteend = function(evt) { 
     console.log("contents of file now 'some sample text'"); 
     writer.truncate(11); 
     writer.onwriteend = function(evt) { 
      console.log("contents of file now 'some sample'"); 
      writer.seek(4); 
      writer.write(" different text"); 
      writer.onwriteend = function(evt){ 
       console.log("contents of file now 'some different text'"); 
      } 
     }; 
    }; 
    writer.write("some sample text"); 
} 

function fail(error) { 
    console.log(error.code); 
} 

回答

2

我不是100%肯定,但WP7在其他平台上,您不能写入www目录,因为它只是应用程序的一部分。我确定这段代码正在工作,但它正在写出你的持久性文件存储。

+0

你完全正确,谢谢。 – lcfb 2012-04-17 13:35:17

相关问题