admin管理员组文章数量:1307608
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 working...
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 working...
Share Improve this question asked Apr 5, 2011 at 11:20 theJavatheJava 15k48 gold badges134 silver badges174 bronze badges 1- are you creating a temp file first? Titanium.Filesystem.createTempFile() – rivenate247 Commented Apr 5, 2011 at 17:26
2 Answers
Reset to default 7Try 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.
本文标签: javascriptappcelerator titanium Creating a new fileStack Overflow
版权声明:本文标题:javascript - appcelerator titanium: Creating a new file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741827547a2399734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论