jodd.io.FileUtil.delete()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中jodd.io.FileUtil.delete()方法的一些代码示例,展示了FileUtil.delete()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.delete()方法的具体详情如下:
包路径:jodd.io.FileUtil
类名称:FileUtil
方法名:delete

FileUtil.delete介绍

[英]Smart delete of destination file or directory.
[中]智能删除目标文件或目录。

代码示例

代码示例来源:origin: redisson/redisson

public static void delete(File dest) throws IOException {
  delete(dest, fileUtilParams);
}

代码示例来源:origin: oblac/jodd

@Test
void testZipBuilderFile() throws IOException {
  File zipFile = new File(dataRoot, "test.zip");
  ZipBuilder.createZipFile(zipFile)
    .add(new File(dataRoot, "sb.data"))
      .path("sbdata").comment("This is sb data file").save()
    .add(new File(dataRoot, "file"))
      .path("folder").comment("This is a folder and all its files").save()
    .toZipFile();
  assertTrue(zipFile.exists());
  ZipUtil.unzip(zipFile, new File(dataRoot), "sbda*");
  assertTrue(new File(dataRoot, "sbdata").exists());
  assertFalse(new File(dataRoot, "folder").exists());
  ZipUtil.unzip(zipFile, new File(dataRoot));
  assertTrue(new File(dataRoot, "sbdata").exists());
  assertTrue(new File(dataRoot, "folder").exists());
  assertTrue(new File(new File(dataRoot, "folder"), "a.png").exists());
  // cleanup
  FileUtil.delete(new File(dataRoot, "sbdata"));
  FileUtil.deleteDir(new File(dataRoot, "folder"));
  FileUtil.delete(zipFile);
}

代码示例来源:origin: redisson/redisson

public static void delete(String dest) throws IOException {
  delete(file(dest), fileUtilParams);
}

代码示例来源:origin: oblac/jodd

FileUtil.delete(new File(dataRoot, "sbdata"));
FileUtil.deleteDir(new File(dataRoot, "folder"));
FileUtil.deleteDir(new File(dataRoot, "folder2"));
FileUtil.delete(zipFile);

代码示例来源:origin: redisson/redisson

public static void delete(String dest, FileUtilParams params) throws IOException {
  delete(file(dest), params);
}

代码示例来源:origin: oblac/jodd

/**
 * @see #delete(File)
 */
public static void delete(final String dest) throws IOException {
  delete(file(dest));
}

代码示例来源:origin: oblac/jodd

@Test
void testZip() throws IOException {
  ZipUtil.zip(new File(dataRoot, "sb.data"));
  File zipFile = new File(dataRoot, "sb.data.zip");
  assertTrue(zipFile.exists());
  // cleanup
  FileUtil.delete(zipFile);
  ZipUtil.zip(new File(dataRoot, "file"));
  zipFile = new File(dataRoot, "file.zip");
  assertTrue(zipFile.exists());
  // cleanup
  FileUtil.delete(zipFile);
}

代码示例来源:origin: oblac/jodd

@Test
void testZlib() throws IOException {
  ZipUtil.zlib(new File(dataRoot, "sb.data"));
  File zlibFile = new File(dataRoot, "sb.data.zlib");
  assertTrue(zlibFile.exists());
  // cleanup
  FileUtil.delete(zlibFile);
}

代码示例来源:origin: oblac/jodd

@Test
void testFileManipulation() throws IOException {
  FileUtil.copy(new File(dataRoot, "sb.data"), new File(dataRoot, "sb1.data"));
  assertFalse(FileUtil.isNewer(new File(dataRoot, "sb.data"), new File(dataRoot, "sb1.data")));
  assertFalse(FileUtil.isOlder(new File(dataRoot, "sb.data"), new File(dataRoot, "sb1.data")));
  FileUtil.delete(new File(dataRoot, "sb1.data"));
}

代码示例来源:origin: oblac/jodd

@Test
void testZipDir() throws IOException {
  ZipUtil.zip(new File(dataRoot));
  File zipFile = new File(dataRoot + ".zip");
  assertTrue(zipFile.exists());
  int directoryCount = 0;
  try (ZipFile zipfile = new ZipFile(zipFile)) {
    for (Enumeration<? extends ZipEntry> entries = zipfile.entries(); entries.hasMoreElements(); ) {
      ZipEntry zipEntry = entries.nextElement();
      if (zipEntry.isDirectory()) {
        directoryCount++;
        assertTrue(zipEntry.getName().equals("data/") || zipEntry.getName().equals("data/file/"));
      }
    }
  }
  assertEquals(2, directoryCount);
  // cleanup
  FileUtil.delete(zipFile);
}

代码示例来源:origin: oblac/jodd

@Test
void testGzip() throws IOException {
  ZipUtil.gzip(new File(dataRoot, "sb.data"));
  File gzipFile = new File(dataRoot, "sb.data.gz");
  assertTrue(gzipFile.exists());
  FileUtil.move(gzipFile, new File(dataRoot, "sb2.data.gz"));
  ZipUtil.ungzip(new File(dataRoot, "sb2.data.gz"));
  File data = new File(dataRoot, "sb2.data");
  assertTrue(data.exists());
  byte[] data2Bytes = FileUtil.readBytes(data);
  byte[] data1Bytes = FileUtil.readBytes(new File(dataRoot, "sb.data"));
  assertTrue(Arrays.equals(data1Bytes, data2Bytes));
  // cleanup
  FileUtil.delete(new File(dataRoot, "sb2.data"));
  FileUtil.delete(new File(dataRoot, "sb2.data.gz"));
}

代码示例来源:origin: oblac/jodd

@Test
void testUnicodeString() {
  String s = "This is a test file\nIt only has\nthree lines!!";
  char[] buf = s.toCharArray();
  buf[0] = 256;
  s = new String(buf);
  try {
    FileUtil.writeString(dataRoot + "/test2.txt", s, "UTF-16");
  } catch (Exception ex) {
    fail("FileUtil.writeString " + ex.toString());
  }
  String s2 = null;
  try {
    s2 = FileUtil.readString(dataRoot + "/test2.txt", "UTF-16");
  } catch (Exception ex) {
    fail("FileUtil.readString " + ex.toString());
  }
  assertEquals(s, s2);
  try {
    FileUtil.delete(dataRoot + "/test2.txt");
  } catch (IOException ioex) {
    fail("FileUtil.delete" + ioex.toString());
  }
}

代码示例来源:origin: oblac/jodd

FileUtil.delete(dataRoot + "/test.txt");
} catch (IOException ioex) {
  fail("FileUtil.delete" + ioex.toString());

代码示例来源:origin: oblac/jodd

@Test
void testDirWatcher() throws IOException {
  DirWatcher dirWatcher = new DirWatcher(dataRoot, "*.md");
  final StringBuilder sb = new StringBuilder();
  dirWatcher.register(event -> sb.append(event.type().name() + ":" + event.target().getName() + "\n"));
  dirWatcher.start(100);
  File destFile = new File(dataRoot, "jodd.md");
  FileUtil.writeString(destFile, "#Jodd");
  ThreadUtil.sleep(600);
  FileUtil.writeString(destFile, "#Jodd2");
  ThreadUtil.sleep(600);
  FileUtil.delete(destFile);
  ThreadUtil.sleep(600);
  dirWatcher.stop();
  assertEquals(
      DirWatcherEvent.Type.CREATED + ":jodd.md\n" +
      DirWatcherEvent.Type.MODIFIED + ":jodd.md\n" +
      DirWatcherEvent.Type.DELETED + ":jodd.md\n",
      sb.toString());
}

代码示例来源:origin: oblac/jodd

@Test
void testDirWatcherWithFile() throws IOException {
  DirWatcher dirWatcher = new DirWatcher(dataRoot)
      .monitor("*.md")
      .useWatchFile("watch.txt");
  final StringBuilder sb = new StringBuilder();
  dirWatcher.register(
    event -> sb.append(event.type().name() + ":" + event.target().getName() + "\n"));
  dirWatcher.start(100);
  File watchFile = new File(dataRoot, "watch.txt");
  File destFile = new File(dataRoot, "jodd.md");
  FileUtil.writeString(destFile, "#Jodd");
  FileUtil.touch(watchFile);
  ThreadUtil.sleep(600);
  FileUtil.writeString(destFile, "#Jodd2");
  ThreadUtil.sleep(600);
  FileUtil.delete(destFile);
  FileUtil.touch(watchFile);
  ThreadUtil.sleep(600);
  dirWatcher.stop();
  assertEquals(
      DirWatcherEvent.Type.CREATED + ":jodd.md\n" +
      //DirWatcher.Event.MODIFIED + ":jodd.md\n" +
      DirWatcherEvent.Type.DELETED + ":jodd.md\n",
      sb.toString());
}

代码示例来源:origin: yandex-qatools/embedded-services

private void removeLockFile(MongodConfigBuilder builder) {
  final File lockFile = Paths.get(dataDirectory, "mongod.lock").toFile();
  try {
    delete(lockFile);
  } catch (Exception e) {
    logger.warn("No lock file found for embedded mongodb or removal failed: " + e.getMessage());
  }
}

代码示例来源:origin: ru.yandex.qatools.embed/embedded-services

private void removeLockFile(MongodConfigBuilder builder) {
  final File lockFile = Paths.get(dataDirectory, "mongod.lock").toFile();
  try {
    delete(lockFile);
  } catch (Exception e) {
    logger.warn("No lock file found for embedded mongodb or removal failed: " + e.getMessage());
  }
}

代码示例来源:origin: org.jodd/jodd-core

/**
 * @see #delete(File)
 */
public static void delete(final String dest) throws IOException {
  delete(file(dest));
}

相关文章