Currently, I am in the process of developing an Excel application on a mobile device. Initially, I'm testing it out on Android, but the aim is to ensure compatibility with iOS devices as well.
To build this app, I referred to the official documentation and used the following code snippet:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
console.log('file system open: ' + fs.name);
fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) {
console.log("fileEntry is file?" + fileEntry.isFile.toString());
fileEntry.name == 'someFile.txt'
fileEntry.fullPath == '/someFile.txt'
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function() {
console.log("Successful file write...");
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
console.log("Successful file read: " + this.result);
//displayFileData(fileEntry.fullPath + ": " + this.result);
};
reader.readAsText(file);
},);
};
fileWriter.onerror = function (e) {
console.log("Failed file write: " + e.toString());
};
let dataObj = new Blob(['some file data'], { type: 'text/plain' });
fileWriter.write(dataObj);
});
});
});
I attempted to modify the initial code block with the following lines, however, I encountered the same outcome:
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (fs) {
console.log('file system open: ' + fs.name);
fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) { ...
The console output from my attempts was as follows:
file system open: persistent
fileEntry is file?true
Successful file write...
Successful file read: some file data
Although the file appears to be successfully created and readable, no prompt or indication is provided. Upon navigating to my files at Android/data/com.myapp.app/files, I couldn't locate any file present there.