当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils类代码示例

本文整理汇总了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;
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:32,代码来源:Utils.java

示例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;
}
 
开发者ID:Webreaper,项目名称:GooglePhotoSync,代码行数:18,代码来源:FileUtilities.java

示例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);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:11,代码来源:NativeLocalTrashFeature.java

示例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);
    }
}
 
开发者ID:ijh165,项目名称:Gamma-Music-Manager,代码行数:18,代码来源:FileManager.java

示例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;
	}
}
 
开发者ID:wavinsun,项目名称:MUtils,代码行数:19,代码来源:DesktopUtil.java

示例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);
		}
	}
}
 
开发者ID:phon-ca,项目名称:phon,代码行数:12,代码来源:DesktopProject.java

示例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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:31,代码来源:PathManager.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:30,代码来源:PathManager.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:42,代码来源:PathManager.java


注:本文中的com.sun.jna.platform.FileUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。