Я хочу создать текстовый файл в моем приложении cordova / phonegap, в котором будет храниться простой текст.Я искал вокруг и вряд ли могу найти какие-либо примеры, показывающие процесс этого.Я использую этот код, когда я нажимаю «записать файл», предупреждение показывает, что файл был сохранен в «file: ///data/user/0/com.adobe.phonegap.app/files/files/hello_world.txtно когда я проверяю папку, там ничего нет.Вот код, который я использую.
Я мой config.xml
<preference name="AndroidPersistentFileLocation" value="Internal" />
Моя кнопка HTML
<button class="btn-lg btn-success" onclick="saveFile('hello_world.txt', 'This is Dummy Content')">Write File</button>
Скрипт, который я использую
function saveFile(fileName, fileData) {
// Get access to the file system
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
// Create the file.
fileSystem.root.getFile(fileName, {create: true, exclusive: false}, function (entry) {
// After you save the file, you can access it with this URL
var myFileUrl = entry.toURL()
entry.createWriter(function (writer) {
writer.onwriteend = function (evt) {
alert("Successfully saved file to " + myFileUrl)
}
// Write to the file
writer.write(fileData)
}, function (error) {
alert("Error: Could not create file writer, " + error.code)
})
}, function (error) {
alert("Error: Could not create file, " + error.code)
})
}, function (evt) {
alert("Error: Could not access file system, " + evt.target.error.code)
})
}