本文整理汇总了Java中com.sun.jna.platform.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于com.sun.jna.platform包,在下文中一共展示了FileUtils类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: trash
import com.sun.jna.platform.FileUtils; //导入依赖的package包/类
@Override
public void trash(final Local file) throws LocalAccessDeniedException {
try {
FileUtils.getInstance().moveToTrash(new File[]{new File(file.getAbsolute())});
}
catch(IOException e) {
log.warn(String.format("Failed to move %s to Trash", file.getName()));
new DefaultLocalTrashFeature().trash(file);
}
}
示例4: 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);
}
}
示例5: moveToTrash
import com.sun.jna.platform.FileUtils; //导入依赖的package包/类
/**
* Move to trash
*
* @param file
* @return
*/
public static boolean moveToTrash(File file) {
File[] files = new File[1];
files[0] = file;
try {
FileUtils.getInstance().moveToTrash(files);
return true;
} catch (Exception e) {
return false;
} finally {
files[0] = null;
}
}
示例6: 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);
}
}
}
示例7: getUtilClassPath
import com.sun.jna.platform.FileUtils; //导入依赖的package包/类
@NotNull
public static Collection<String> getUtilClassPath() {
final List<Class<?>> classes = Arrays.asList(
PathManager.class, // module 'util'
NotNull.class, // module 'annotations'
SystemInfoRt.class, // module 'util-rt'
Document.class, // jDOM
Appender.class, // log4j
THashSet.class, // trove4j
PicoContainer.class, // PicoContainer
TypeMapper.class, // JNA
FileUtils.class, // JNA (jna-utils)
PatternMatcher.class // OROMatcher
);
final Set<String> classPath = new HashSet<String>();
for (Class<?> aClass : classes) {
final String path = getJarPathForClass(aClass);
if (path != null) {
classPath.add(path);
}
}
final String resourceRoot = getResourceRoot(PathManager.class, "/messages/CommonBundle.properties"); // platform-resources-en
if (resourceRoot != null) {
classPath.add(new File(resourceRoot).getAbsolutePath());
}
return Collections.unmodifiableCollection(classPath);
}
示例8: getUtilClassPath
import com.sun.jna.platform.FileUtils; //导入依赖的package包/类
@Nonnull
public static Collection<String> getUtilClassPath() {
final Class<?>[] classes = {PathManager.class, // module 'util'
Nonnull.class, // module 'annotations'
SystemInfoRt.class, // module 'util-rt'
Document.class, // jDOM
Appender.class, // log4j
THashSet.class, // trove4j
PicoContainer.class, // PicoContainer
TypeMapper.class, // JNA
FileUtils.class, // JNA (jna-platform)
PatternMatcher.class // OROMatcher
};
final Set<String> classPath = new HashSet<String>();
for (Class<?> aClass : classes) {
final String path = getJarPathForClass(aClass);
if (path != null) {
classPath.add(path);
}
}
final String resourceRoot = getResourceRoot(PathManager.class, "/messages/CommonBundle.properties"); // platform-resources-en
if (resourceRoot != null) {
classPath.add(new File(resourceRoot).getAbsolutePath());
}
return Collections.unmodifiableCollection(classPath);
}
示例9: getUtilClassPath
import com.sun.jna.platform.FileUtils; //导入依赖的package包/类
@NotNull
public static Collection<String> getUtilClassPath() {
final Class<?>[] classes = {
PathManager.class, // module 'util'
Flow.class, // module 'annotations'
SystemInfoRt.class, // module 'util-rt'
Document.class, // jDOM
Appender.class, // log4j
THashSet.class, // trove4j
PicoContainer.class, // PicoContainer
TypeMapper.class, // JNA
FileUtils.class, // JNA (jna-platform)
PatternMatcher.class, // OROMatcher
Snappy.class // Snappy
};
final Set<String> classPath = new HashSet<String>();
for (Class<?> aClass : classes) {
final String path = getJarPathForClass(aClass);
if (path != null) {
classPath.add(path);
}
}
final String annotationsRoot = getJarPathForClass(Flow.class);
if (annotationsRoot != null && !annotationsRoot.endsWith(".jar")) {
// We're running IDEA built from sources. Flow.class is under annotations-common, and NotNull.class is under annotations. Add both
// roots to classpath.
final File notNullRoot = new File(new File(annotationsRoot).getParentFile(), "annotations");
if (notNullRoot.exists()) {
classPath.add(notNullRoot.getAbsolutePath());
}
}
final String resourceRoot = getResourceRoot(PathManager.class, "/messages/CommonBundle.properties"); // platform-resources-en
if (resourceRoot != null) {
classPath.add(new File(resourceRoot).getAbsolutePath());
}
return Collections.unmodifiableCollection(classPath);
}