- This topic has 0 replies, 1 voice, and was last updated 10 years, 6 months ago by pratiti.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
pratitiMemberHello,
I need to create a text file in internal storage of mobile device and then write to it and save it via my code.
I’m trying with this example from cordova docs, but this isn’t working:
<script type="text/javascript" charset="utf-8"> // Wait for device API libraries to load // document.addEventListener("deviceready", onDeviceReady, false); // device APIs are available // function onDeviceReady() { alert("ready"); window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } function gotFS(fileSystem) { alert("gotFs: " + fileSystem.name); fileSystem.root.getFile(example.txt, {create: true, exclusive: false}, gotFileEntry, fail); } function gotFileEntry(fileEntry) { alert("gotFileEntry: " + fileEntry.name); 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) { alert("fail"); console.log(error.code); } </script>
This gives an alert of ‘success’ for writing, but when I run this on device, it gives ‘fail’ alert message. Also, I’m not clear about the location it uses to save the file created.
Please help.
Thanks in advance. -
AuthorPosts
Viewing 1 post (of 1 total)