Vote up!
0 Votes
1 Replies

File creation issue - Studio 6.5

Question asked by Magesh Rathnam on Apr 04, 2017 11:29 EDT

Hi – Am using Kony Studio 6.5. I have been trying to use file/directory creation. It returns false, but am not sure what is the reason. Am trying in Android and iOS.  Can someone guide me on how to see the issue? I have set 'WRITE_EXTERNAL_STORAGE' permission as well, in android, though am not sure if it is really needed. I have problem in ios as well. It goes into file not exists or dir not exists loop, but does not create them. I think file creation fails, because dir creation was unsuccessful. Code snippet: var path =; var testFilePath = path+"/test/test.txt"; function formPreInit(){ kony.print("Inside Form Pre Init"); var dirLoc = path + "/test"; kony.print("dirLoc is: " + dirLoc); var directoryPath = new; if(!directoryPath.exists()) { //Create the new dir, if it does not exist. var dirPath = new; var dirCreationSuccess = dirPath.createDirectory(test); kony.print("dirCreationSuccess :: " + dirCreationSuccess); var dataToWrite = "Write test"; saveDataToFile(dataToWrite); } //Create the file at the path, if it does not exist //Write to the file, the data passed function saveDataToFile(dataToWrite) { kony.print("Inside saveDataToFile"); var filePath = new; if (!filePath.exists()){ kony.print("File does not exist. Creating new one"); var success = filePath.createFile(); alert("File created " + success); } var dataAdded = filePath.write(dataToWrite,true); alert("IS DATA ADDED >>>>>>>"+dataAdded); }  

Posted In
Kony Inc Kony Studio
Vote up!
0 votes
Vote down!

Hi Magesh,

Below is the code to create file in the file system,

var path =;                                                                                                            //create the file in directory photos                                                                                                                                           var myfile = + "/photos/" + lMediaName + ".jpg");                                                                           var filecreated = myfile.createFile();

Where in case of Windows and Android if the given directory is not availabel then system will create the directory and will write the file. where in case of iOS if the directory is not avaialble it will return false.

To make if work in iOS

Please add the below code snippet before

var myfile = + "/photos/" + lMediaName + ".jpg");"

var myDirectory = + "/photos/");
var directorycreated = myDirectory.createDirectory();

As in case of iPhone, file won't be created if directory does not exist.



Replied by: Apr 06, 2017 00:41 EDT