iPad simulator crashes when trying to create a File
Hello I've run into this problem which is most probably my fault but any help/advice would be great.
I've got this piece of code which I run after user pushes the button, it does take text from the Textarea and it should create a text file inside appsDir for later usage.
//listen to tap
btn1.addEventListener("click",function(){
var text = txtfd.value;
if(text !== null)
{
var f = Titanium.Filesystem.createFile("test.txt");
f.createFile();
f.write(text);
if(f.exists())
{
alertDialog = Titanium.UI.createAlertDialog({
title: 'Be Happy!',
message: 'File exists!',
buttonNames: ['Yeah!']
});
alertDialog.show();
}
else
{
alertDialog = Titanium.UI.createAlertDialog({
title: 'Be Worried!',
message: 'File does not exist!',
buttonNames: ['Doh!']
});
alertDialog.show();
}
}
});
1 Answer
-
Accepted Answer
Try this
//listen to tap btn1.addEventListener("click",function(){ var text = txtfd.value; if(text !== null) { var f = Titanium.Filesystem.getFile('test.txt'); f.write(text); if(f.exists()) { alertDialog = Titanium.UI.createAlertDialog({ title: 'Be Happy!', message: 'File exists!', buttonNames: ['Yeah!'] }); alertDialog.show(); } else { alertDialog = Titanium.UI.createAlertDialog({ title: 'Be Worried!', message: 'File does not exist!', buttonNames: ['Doh!'] }); alertDialog.show(); } } });