本文整理汇总了Java中com.sun.jna.platform.FileUtils.hasTrash方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.hasTrash方法的具体用法?Java FileUtils.hasTrash怎么用?Java FileUtils.hasTrash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jna.platform.FileUtils
的用法示例。
在下文中一共展示了FileUtils.hasTrash方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteToTrash
import com.sun.jna.platform.FileUtils; //导入方法依赖的package包/类
/**
* Deletes a file or directory. If a system trash directory is available,
* the file or directory will be moved there instead.
* @param file the file or directory to delete
* @return true if moved to trash, and false if deleted
* @throws IOException if given file does not exist
*/
public static boolean deleteToTrash(File file) throws IOException {
if (file == null)
throw new IOException("File cannot be null.");
if (!file.exists())
throw new IOException(String.format("File '%s' does not exist.", file.getAbsolutePath()));
// move to system trash, if possible
FileUtils fileUtils = FileUtils.getInstance();
if (fileUtils.hasTrash()) {
try {
fileUtils.moveToTrash(new File[] { file });
return true;
} catch (IOException e) {
Log.warn(String.format("Failed to move file '%s' to trash.", file.getAbsolutePath()), e);
}
}
// delete otherwise
if (file.isDirectory())
deleteDirectory(file);
else
file.delete();
return false;
}
示例2: moveToTrash
import com.sun.jna.platform.FileUtils; //导入方法依赖的package包/类
public static boolean moveToTrash(File fileToDelete)
{
FileUtils fileUtils = FileUtils.getInstance();
if (fileUtils.hasTrash())
{
try
{
fileUtils.moveToTrash( new File[] { fileToDelete } );
return true;
} catch (IOException ioe)
{
}
}
return false;
}
示例3: removeFile
import com.sun.jna.platform.FileUtils; //导入方法依赖的package包/类
/**
* Move to trash if trash exist in OS, else remove from file system
*
* @param fileToRemove: file to be removed
* @return true if file is removed successfully
* @throws IOException
*/
public static boolean removeFile(File fileToRemove) throws IOException {
FileUtils fileUtils = FileUtils.getInstance();
if (fileUtils.hasTrash()) {
fileUtils.moveToTrash( new File[]{fileToRemove} );
return true;
}
else {
return deleteFolderOrFile(fileToRemove);
}
}
示例4: moveToTrash
import com.sun.jna.platform.FileUtils; //导入方法依赖的package包/类
private void moveToTrash(File[] files) throws IOException {
FileUtils fileUtils = FileUtils.getInstance();
if(fileUtils.hasTrash()) {
fileUtils.moveToTrash(files);
} else {
// delete
for(File file:files) {
org.apache.commons.io.FileUtils.forceDelete(file);
}
}
}