Reputation: 684
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");
}
Upvotes: 2
Views: 1324
Reputation: 116020
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 simply hallo.text
to create the file in your sandboxed file system. Do not use an absolute file:
path.
Additionally, your error function, fail
, is probably being supplied with an argument with error info. Try adding an argument to the function like function fail(error) ...
and printing out error
for more debugging info.
Upvotes: 2
Reputation: 572
First of all, make sure "you" have rights to write in the destination folder (your device may need to have the root permissions to write in some folders).
After that, follow the instructions from here: http://www.anddev.org/working_with_files-t115.html
Upvotes: 0