删除applicationDataDirectory中的文件

时间:2012-05-14 21:44:01

标签: caching mobile titanium delete-file

在钛中,删除应用程序数据目录中的特定文件的最佳方法是什么?

2 个答案:

答案 0 :(得分:3)

最好的方法就是:

var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename);
if ( file.exists() ) {
     file.deleteFile();
}

有关详细信息Titanium.Filesystem.File

答案 1 :(得分:1)

删除文件很简单,

var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'delete_me.txt');
f.write('foo');
// make sure there's content there so we're sure the file exists
// Before deleting, maybe we could confirm the file exists and is writable
// but we don't really need to as deleteFile() would just return false if it failed
if (f.exists() && f.writeable) {
    var success = f.deleteFile();
    Ti.API.info((success == true) ? 'success' : 'fail'); // outputs 'success'
}

FileSystems上最好的材料之一:https://wiki.appcelerator.org/display/guides/Filesystem+Access+and+Storage#FilesystemAccessandStorage-Deletingfiles