Reputation: 3
I've been trying to make an app write some text to a file under phonegap/cordova 1.6.0 for windows phone, using the examples from the phonegap/cordova API, but without any luck.
The file it's a .txt that was created manually in the 'www' folder, and by using console.log and the .onerror and .onwriteend event functions I'm able to see that the writer supposedly completes the task of writing to the file with success, but the content of the file doesn't change at all.
Does anyone know a reason for this?
Here's the example from the API (where you see "readme.txt" I used "/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);
}
Upvotes: 0
Views: 778
Reputation: 23273
I'm not 100% sure about WP7 but in other platforms you can't write to the www directory as it is a write only part of your application. I'm sure this code is working but it is writing out to your persistent file store.
Upvotes: 2