org.apache.commons.io.FileUtils.getFile()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(638)

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

FileUtils.getFile介绍

[英]Construct a file from the set of name elements.
[中]从名称元素集构造一个文件。

代码示例

代码示例来源:origin: square/spoon

private void generateCssFromLess() {
 try {
  LessCompiler compiler = new LessCompiler();
  String less = Resources.toString(getClass().getResource("/spoon.less"), UTF_8);
  String css = compiler.compile(less);
  File cssFile = FileUtils.getFile(output, STATIC_DIRECTORY, "spoon.css");
  FileUtils.writeStringToFile(cssFile, css, UTF_8);
 } catch (Exception e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: square/spoon

this.singleInstrumentationCall = singleInstrumentationCall;
serial = SpoonUtils.sanitizeSerial(serial);
this.work = FileUtils.getFile(output, TEMP_DIR, serial);
this.junitReport = FileUtils.getFile(output, JUNIT_DIR, serial + ".xml");
this.imageDir = FileUtils.getFile(output, IMAGE_DIR, serial);
this.fileDir = FileUtils.getFile(output, FILE_DIR, serial);
this.coverageDir = FileUtils.getFile(output, COVERAGE_DIR, serial);
this.testRunListeners = testRunListeners;
this.grantAll = grantAll;

代码示例来源:origin: square/spoon

private void saveRawLog() {
 for (Map.Entry<String, DeviceResult> resultEntry : summary.getResults().entrySet()) {
  String serial = resultEntry.getKey();
  DeviceResult result = resultEntry.getValue();
  for (Map.Entry<DeviceTest, DeviceTestResult> entry : result.getTestResults().entrySet()) {
   DeviceTest test = entry.getKey();
   File rawFile = FileUtils.getFile(output, "logs", serial, test.getClassName(),
     test.getMethodName() + ".log");
   saveRawLogFile(rawFile, entry.getValue());
  }
 }
}

代码示例来源:origin: square/spoon

private void generateDeviceHtml(MustacheFactory mustacheFactory) {
 Mustache mustache = mustacheFactory.compile("page/device.html");
 for (Map.Entry<String, DeviceResult> entry : summary.getResults().entrySet()) {
  String serial = entry.getKey();
  HtmlDevice scope = HtmlDevice.from(serial, entry.getValue(), output);
  File file = FileUtils.getFile(output, "device", serial + ".html");
  renderMustacheToFile(mustache, scope, file);
 }
}

代码示例来源:origin: square/spoon

/** Get an {@link com.android.ddmlib.AndroidDebugBridge} instance given an SDK path. */
public static AndroidDebugBridge initAdb(File sdk, Duration timeOut) {
 AndroidDebugBridge.initIfNeeded(false);
 File adbPath = FileUtils.getFile(sdk, "platform-tools", "adb");
 AndroidDebugBridge adb = AndroidDebugBridge.createBridge(adbPath.getAbsolutePath(), false);
 waitForAdb(adb, timeOut);
 return adb;
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testGetFile() {
  final File expected_A = new File("src");
  final File expected_B = new File(expected_A, "main");
  final File expected_C = new File(expected_B, "java");
  assertEquals("A", expected_A, FileUtils.getFile("src"));
  assertEquals("B", expected_B, FileUtils.getFile("src", "main"));
  assertEquals("C", expected_C, FileUtils.getFile("src", "main", "java"));
  try {
    FileUtils.getFile((String[]) null);
    fail("Expected NullPointerException");
  } catch (final NullPointerException e) {
    // expected
  }
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testGetFile_Parent() {
  final File parent = new File("parent");
  final File expected_A = new File(parent, "src");
  final File expected_B = new File(expected_A, "main");
  final File expected_C = new File(expected_B, "java");
  assertEquals("A", expected_A, FileUtils.getFile(parent, "src"));
  assertEquals("B", expected_B, FileUtils.getFile(parent, "src", "main"));
  assertEquals("C", expected_C, FileUtils.getFile(parent, "src", "main", "java"));
  try {
    FileUtils.getFile(parent, (String[]) null);
    fail("Expected NullPointerException");
  } catch (final NullPointerException e) {
    // expected
  }
  try {
    FileUtils.getFile((File) null, "src");
    fail("Expected NullPointerException");
  } catch (final NullPointerException e) {
    // expected
  }
}

代码示例来源:origin: square/spoon

private void generateTestHtml(MustacheFactory mustacheFactory) {
 Mustache mustache = mustacheFactory.compile("page/test.html");
 // Create a set of unique tests.
 Set<DeviceTest> tests = new LinkedHashSet<>();
 for (DeviceResult deviceResult : summary.getResults().values()) {
  tests.addAll(deviceResult.getTestResults().keySet());
 }
 // Generate a page for each one.
 for (DeviceTest test : tests) {
  HtmlTest scope = HtmlTest.from(test, summary, output);
  File file =
    FileUtils.getFile(output, "test", test.getClassName(), test.getMethodName() + ".html");
  renderMustacheToFile(mustache, scope, file);
 }
}

代码示例来源:origin: square/spoon

private void generateLogHtml(MustacheFactory mustacheFactory) {
 Mustache mustache = mustacheFactory.compile("page/log.html");
 for (Map.Entry<String, DeviceResult> resultEntry : summary.getResults().entrySet()) {
  String serial = resultEntry.getKey();
  DeviceResult result = resultEntry.getValue();
  DeviceDetails details = result.getDeviceDetails();
  String name = (details != null) ? details.getName() : serial;
  for (Map.Entry<DeviceTest, DeviceTestResult> entry : result.getTestResults().entrySet()) {
   DeviceTest test = entry.getKey();
   HtmlLog scope = HtmlLog.from(name, test, entry.getValue());
   File file = FileUtils.getFile(output, "logs", serial, test.getClassName(),
     test.getMethodName() + ".html");
   renderMustacheToFile(mustache, scope, file);
  }
 }
}

代码示例来源:origin: square/spoon

continue; // Do not make an animated GIF if there is only one screenshot.
File animatedGif = FileUtils.getFile(imageDir, deviceTest.getClassName(),
  deviceTest.getMethodName() + ".gif");
createAnimatedGif(screenshots, animatedGif);

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

protected String wrapPath(String path) {
  // Ensure the `path` exists
  try {
    FileUtils.forceMkdir(FileUtils.getFile(path));
  } catch (IOException e) {
    throw new BackendException(e.getMessage(), e);
  }
  // Join with store type
  return Paths.get(path, this.store).toString();
}

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

public static void clearDir(String tempDir) {
  File file = FileUtils.getFile(tempDir);
  if (!file.exists()) {
    return;
  }
  try {
    FileUtils.forceDelete(file);
  } catch (IOException e) {
    throw new BackendException(e);
  }
}

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

@AfterClass
public static void clear() throws IOException {
  /*
   * The FileUtils.forceDelete() can only accept a `File`
   * in `org.apache.commons.io` version 2.4
   */
  FileUtils.forceDelete(FileUtils.getFile(DB_PATH));
}

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

public static List<PaloFile> scan(String path, List<String> tableDirs) {
  File directory = FileUtils.getFile(path);
  if (!directory.exists()) {
    return ImmutableList.of();
  }
  File[] subDirs = directory.listFiles((dir, name) -> {
    return tableDirs.contains(name);
  });
  if (subDirs == null || subDirs.length == 0) {
    return ImmutableList.of();
  }
  List<PaloFile> paloFiles = new ArrayList<>(subDirs.length);
  for (File subDir : subDirs) {
    String[] fileNames = subDir.list();
    if (fileNames == null) {
      continue;
    }
    for (String fileName : fileNames) {
      paloFiles.add(new PaloFile(path, subDir.getName(), fileName));
    }
  }
  /*
   * Sort palo file by updated time in asc order,
   * let old files to be processed in priority
   */
  paloFiles.sort((file1, file2) -> {
    return (int) (file1.lastModified() - file2.lastModified());
  });
  return paloFiles;
}

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

public static boolean isInScope(String scopeLocation, String fileFullPath) throws IOException {
  if (FileUtils.getFile(fileFullPath).getCanonicalPath().startsWith(scopeLocation)) {
    return true;
  }
  return false;
}

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

public String readFile(String fileNameWithPath) {
    try {
      return FileUtils.readFileToString(FileUtils.getFile(fileNameWithPath));
    } catch (IOException ex) {
      _logger.error("Exception,", ex);
      return null;
    }
  }
}

代码示例来源:origin: com.baidu.hugegraph/hugegraph-rocksdb

protected String wrapPath(String path) {
  // Ensure the `path` exists
  try {
    FileUtils.forceMkdir(FileUtils.getFile(path));
  } catch (IOException e) {
    throw new BackendException(e.getMessage(), e);
  }
  // Join with store type
  return Paths.get(path, this.store).toString();
}

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

private void writeFileToDisk(String writeOnDir, MetricsCsv metricsCsv) throws IOException {
  File targetFile = FileUtils.getFile(FileUtils.getFile(writeOnDir).getCanonicalPath() + File.separator
      + metricsCsv.getFileName());
  _logger.debug("FileName:{}", targetFile.getCanonicalPath());
  FileUtils.getFile(targetFile.getParentFile()).mkdirs();
  FileUtils.writeStringToFile(targetFile, metricsCsv.getData());
  metricsCsv.setFileName(targetFile.getCanonicalPath());
}

代码示例来源:origin: org.kuali.common/kuali-util

public static List<String> getQualifiers(File baseDirectory, ProjectIdentifier project, List<String> includes, List<String> excludes) {
  String resourcePath = ProjectUtils.getResourcePath(project.getGroupId(), project.getArtifactId());
  File resourceDirectory = FileUtils.getFile(baseDirectory, resourcePath);
  return getQualifiers(resourceDirectory, includes, excludes);
}

代码示例来源:origin: org.kuali.common/kuali-util

public static List<String> getQualifiers(File baseDirectory, Project project, List<String> includes, List<String> excludes) {
  String resourcePath = ProjectUtils.getResourcePath(project.getGroupId(), project.getArtifactId());
  File resourceDirectory = FileUtils.getFile(baseDirectory, resourcePath);
  return getQualifiers(resourceDirectory, includes, excludes);
}

相关文章

FileUtils类方法