Learn an easy way to create a file (android,ios,windows) with cordova

Create a file in cordova is pretty easy, use the following code to create file in a specific folder. This code works in all cordova platforms ()

var path = "file:///storage/emulated/0";
var filename = "myfile.txt";

window.resolveLocalFileSystemURL(path, function(dir) {
	dir.getFile(filename, {create:true}, function(fileEntry) {
            // The file has been succesfully created. Use fileEntry to read the content or delete the file
	});
});

Remember that you need the file plugin from cordova, read and learn how to use it here. You can download the file plugin into your project with :

cordova plugin add cordova-plugin-file

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors