Appcelerator的钛:创建一个新的文件 [英] appcelerator titanium: Creating a new file

查看:132
本文介绍了Appcelerator的钛:创建一个新的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建Appcelerator的钛一个新的文件。

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());

以上code不工作...

The Above code is not working...

推荐答案

尝试创建的文件写入到文件之前:

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());
}

这篇关于Appcelerator的钛:创建一个新的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆