Important! A new Community experience launched on September 26, 2017. Read more about it here or continue to Base Camp.
Voting: 
Vote up!
0 Votes
1 Replies

Saving data will persist after App re- installment

Nivrita Parai on Nov 23, 2015 05:05 EST

Posted In
Vote up!
0 votes
Vote down!

Hi Nivrita,

Thank you for contacting community forums.

We can achieve this by using File Api's.Please find below Sample code .

For reading from the file and writting in the file:

Code:

var mainLoc = kony.io.FileSystem.getDataDirectoryPath();

var fileLoc = mainLoc + constants.FILE_PATH_SEPARATOR + "myFile.txt";

try{

var ifFileExists = kony.io.File(fileLoc).exists();

if(ifFileExists) {

var reading = new kony.io.File(myFileLoc).read();

kony.print(JSON.stringify(reading));

if((reading.readAsText()) == "How are you?"){

                alert("writing was successful");

}

}else{

var myFile = new kony.io.File(fileLoc).createFile();

var writing = new kony.io.File(myFileLoc).write("How are you?");

}

Thanks.

Replied by: Dec 04, 2015 07:04 EST