PhoneGap – How to create a new file in assets/www/example/hallo.text
my error is "Error fileSystem"
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
function fail() {
confirm('Error fileSystem');
}
function gotFS(fileSystem) {
fileSystem.root.getFile("file:///android_asset/www/example/hallo.text", {
create: true
}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.write("hallo");
}
The HTML file system API operates in a sandboxed file system. You cannot reference absolute paths with respect to the full filesystem; instead, all of your Web app’s file system exists in a browser-generated subdirectory inside the device’s real firesystem.
This was done deliberately, for security reasons, so that Web apps can only overwrite or read files that they have created. Otherwise, any page on the Web might read all the private contents of your whole hard drive.
You should use an unqualified file path like
www/example/hallo.text(assuming those directories exist) or simplyhallo.textto create the file in your sandboxed file system. Do not use an absolutefile:path.Additionally, your error function,
fail, is probably being supplied with an argument with error info. Try adding an argument to the function likefunction fail(error) ...and printing outerrorfor more debugging info.