2013-07-07 43 views
0

我正在處理目錄中創建文本文件的代碼。無法在手機中的文件夾內創建文本文件

我用google搜索了一下,發現這個代碼準備好了。

但它不工作。

我也用fileSystem.getDirectory,而不是fileSystem.root.getFile

代碼:

function gotFS(fileSystem) { 
    // create dir 
    alert("jjßß") 
    fileSystem.root.getFile("newDir", { 
     create: true, 
     exclusive: false 
    }, gotDirEntry, fail); 
} 

function gotDirEntry(dirEntry) { 
    // create file 
    dirEntry.getFile("newFile.txt", { 
     create: true, 
     exclusive: false 
    }, gotFileEntry, fail); 
} 

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

function gotFileWriter(writer) { 
    writer.onwrite = function (evt) { 
     console.log("write completed"); 
    }; 
    writer.write("some sample text"); 
    writer.abort(); 
} 

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

任何機會,這是爲iOS?如果是這樣的話:你無法寫入應用程序包。 – 2013-07-07 07:46:08

+0

的意思是你可以請解釋更多 – Shruti

+0

我也需要創建一個文件夾,我需要創建文本文件 – Shruti

回答

0

你可以試試下面的代碼:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) 
{ 
    var fullPathtowrite = fs.root.fullPath; //this is the "working" directory for saving files 
} 
相關問題