org.matsim.core.utils.io.IOUtils.deleteDirectoryRecursively()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(123)

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

IOUtils.deleteDirectoryRecursively介绍

[英]Deletes a directory tree recursively. Should behave like rm -rf, i.e. there should not be any accidents like following symbolic links.
[中]递归删除目录树。应该像rm-rf一样,也就是说,不应该有任何类似以下符号链接的事故。

代码示例

代码示例来源:origin: matsim-org/matsim

@Override
  public void actionPerformed( ActionEvent e ) {
    if ( !Gui.this.txtOutput.getText().isEmpty() ) {
      int i = JOptionPane.showOptionDialog( Gui.this, "Do you really want to delete the output directory? This action cannot be undone.", "Delete Output Directory", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[]{"Cancel", "Delete"}, "Cancel" );
      if ( i == 1 ) {
        try {
          IOUtils.deleteDirectoryRecursively( new File( Gui.this.txtOutput.getText() ).toPath() );
        } catch ( Exception ex ) {
          ex.printStackTrace();
        }
      }
    }
  }
} );

代码示例来源:origin: matsim-org/matsim

log.info("###########################################################");
  System.out.flush();
  IOUtils.deleteDirectoryRecursively(outputDir.toPath());
  break;
default:

代码示例来源:origin: matsim-org/matsim

private void createOutputDirectory() {
  if ((!this.outputDirCreated) && (this.outputDirectory != null)) {
    File directory = new File(this.outputDirectory);
    if (directory.exists()) {
      IOUtils.deleteDirectoryRecursively(directory.toPath());
    }
    this.outputDirCreated = directory.mkdirs();
    Assert.assertTrue("Could not create the output directory " + this.outputDirectory, this.outputDirCreated);
  }
}

代码示例来源:origin: matsim-org/matsim

private void createOutputDirectory() {
  if ((!this.outputDirCreated) && (this.outputDirectory != null)) {
    File directory = new File(this.outputDirectory);
    if (directory.exists()) {
      IOUtils.deleteDirectoryRecursively(directory.toPath());
    }
    this.outputDirCreated = directory.mkdirs();
    assertTrue("Could not create the output directory " + this.outputDirectory, this.outputDirCreated);
  }
}

代码示例来源:origin: matsim-org/matsim

/**
 * @author mrieser
 */
@Test(expected = UncheckedIOException.class)
public void testDeleteDir_InexistentDir() {
  String outputDir = utils.getOutputDirectory();
  String testDir = outputDir + "a";
  File dir = new File(testDir);
  IOUtils.deleteDirectoryRecursively(dir.toPath());
  Assert.assertFalse(dir.exists());
}

代码示例来源:origin: matsim-org/matsim

/**
 * @author mrieser
 */
@Test
public void testDeleteDir() throws IOException {
  String outputDir = utils.getOutputDirectory();
  String testDir = outputDir + "a";
  String someFilename = testDir + "/a.txt";
  File dir = new File(testDir);
  Assert.assertTrue(dir.mkdir());
  File someFile = new File(someFilename);
  Assert.assertTrue(someFile.createNewFile());
  IOUtils.deleteDirectoryRecursively(dir.toPath());
  Assert.assertFalse(someFile.exists());
  Assert.assertFalse(dir.exists());
}

代码示例来源:origin: matsim-org/matsim

@Test
public void testDeleteIfDirectoryExists() {
  final String outputDirectory = utils.getOutputDirectory();
  IOUtils.deleteDirectoryRecursively(new File( outputDirectory ).toPath());

代码示例来源:origin: matsim-org/matsim

@Test
public void testOverrideIfDirectoryExists() {
  final String outputDirectory = utils.getOutputDirectory();
  IOUtils.deleteDirectoryRecursively(new File( outputDirectory ).toPath());
  // directory creation is a side effect of instanciation...
  new OutputDirectoryHierarchy(
      outputDirectory,
      OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles );
  Assert.assertTrue(
      "Directory was not created",
      new File( outputDirectory ).exists() );
  // put something in the directory
  try ( final BufferedWriter writer = IOUtils.getBufferedWriter( outputDirectory+"/some_file" ) ) {
    writer.write( "stuff" );
  }
  catch (IOException e) {
    throw new UncheckedIOException( e );
  }
  // directory creation is a side effect of instanciation...
  new OutputDirectoryHierarchy(
      outputDirectory,
      OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);
  Assert.assertTrue(
      "Directory was cleared",
      new File( outputDirectory+"/some_file" ).exists() );
}

代码示例来源:origin: matsim-org/matsim

@Test
public void testFailureIfDirectoryExists() {
  final String outputDirectory = utils.getOutputDirectory();
  IOUtils.deleteDirectoryRecursively(new File( outputDirectory ).toPath());
  // directory creation is a side effect of instanciation...
  new OutputDirectoryHierarchy(
      outputDirectory,
      OutputDirectoryHierarchy.OverwriteFileSetting.failIfDirectoryExists );
  Assert.assertTrue(
      "Directory was not created",
      new File( outputDirectory ).exists() );
  // put something in the directory
  try ( final BufferedWriter writer = IOUtils.getBufferedWriter( outputDirectory+"/some_file" ) ) {
    writer.write( "stuff" );
  }
  catch (IOException e) {
    throw new UncheckedIOException( e );
  }
  try {
    // directory creation is a side effect of instanciation...
    new OutputDirectoryHierarchy(
        outputDirectory,
        OutputDirectoryHierarchy.OverwriteFileSetting.failIfDirectoryExists);
  }
  catch ( RuntimeException e ) {
    return;
  }
  Assert.fail( "no exception thrown when directory exists!" );
}

相关文章