开发者

appcelerator titanium: Creating a new file

How to create a new file in appcelerator titanium.

  var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'Settings');
  Ti.API.info("Created Settings: " + Settings.createDirectory());
  Ti.API.info('Settings ' + Settings);
  var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');
  newFile.write('line 1\n');
  Ti.API.info('newfile: '+newFile.read());

The Above code is not workin开发者_高级运维g...


Try creating the file before writing to the file:

var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'Settings');
Ti.API.info("Created Settings: " + Settings.createDirectory());
Ti.API.info('Settings ' + Settings);
var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');

newFile.createFile();

if (newFile.exists()){
    newFile.write('line 1\n');
    Ti.API.info('newfile: '+newFile.read());
}


Using newFile.createFile(); will throw error. It seems depricated in 3.0 as I did not find it woking with me. I tried newfile.write('Some data'); and it worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜