2

在钛中,删除 applicationDataDirectory 中特定文件的最佳方法是什么?

4

2 回答 2

3

最好的方法很简单:

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

有关完整的详细信息Titanium.Filesystem.File

于 2012-05-15T04:40:12.783 回答
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'
}

关于文件系统的最佳材料之一:https ://wiki.appcelerator.org/display/guides/Filesystem+Access+and+Storage#FilesystemAccessandStorage-Deletingfiles

于 2012-09-12T06:53:42.190 回答