java.io.File.getAbsoluteFile()方法的使用及代码示例

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

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

File.getAbsoluteFile介绍

[英]Returns a new file constructed using the absolute path of this file. Equivalent to new File(this.getAbsolutePath()).
[中]返回使用此文件的绝对路径构造的新文件。等效于新文件(this.getAbsolutePath())。

代码示例

代码示例来源:origin: jenkinsci/jenkins

public File getCurrentWorkingDirectory() {
  return new File(".").getAbsoluteFile();
}

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

@SuppressWarnings("ResultOfMethodCallIgnored")
private static File toDirectory(String path) {
  if (path == null) {
    return null;
  }
  File f = new File(path);
  f.mkdirs();
  if (!f.isDirectory()) {
    return null;
  }
  try {
    return f.getAbsoluteFile();
  } catch (Exception ignored) {
    return f;
  }
}

代码示例来源:origin: apache/zookeeper

public AtomicFileOutputStream(File f) throws FileNotFoundException {
  // Code unfortunately must be duplicated below since we can't assign
  // anything
  // before calling super
  super(new FileOutputStream(new File(f.getParentFile(), f.getName()
      + TMP_EXTENSION)));
  origFile = f.getAbsoluteFile();
  tmpFile = new File(f.getParentFile(), f.getName() + TMP_EXTENSION)
      .getAbsoluteFile();
}

代码示例来源:origin: ronmamo/reflections

public static File prepareFile(String filename) {
  File file = new File(filename);
  File parent = file.getAbsoluteFile().getParentFile();
  if (!parent.exists()) {
    //noinspection ResultOfMethodCallIgnored
    parent.mkdirs();
  }
  return file;
}

代码示例来源:origin: alibaba/mdrill

/**
 * Returns true if this package is already installed
 * 
 * @return true if this package is installed
 */
public boolean isInstalled() {
 File packageDir = new File(m_packageHome.getAbsoluteFile() + File.separator
   + m_packageMetaData.get("PackageName") + File.separator + "Description.props");
 return (packageDir.exists());
}

代码示例来源:origin: apache/hbase

protected void createSubDir(String propertyName, Path parent, String subDirName) {
 Path newPath = new Path(parent, subDirName);
 File newDir = new File(newPath.toString()).getAbsoluteFile();
 if (deleteOnExit()) newDir.deleteOnExit();
 conf.set(propertyName, newDir.getAbsolutePath());
}

代码示例来源:origin: apache/geode

@Override
public File getParentFile(final File file) {
 File tmp = file.getAbsoluteFile().getParentFile();
 if (tmp == null) {
  tmp = new File("."); // as a fix for bug #41474 we use "." if getParentFile returns null
 }
 return tmp;
}

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

public GoPluginDescriptor build(File pluginJarFile, boolean isBundledPlugin) {
  if (!pluginJarFile.exists()) {
    throw new RuntimeException(String.format("Plugin jar does not exist: %s", pluginJarFile.getAbsoluteFile()));
  }
  try (JarFile jarFile = new JarFile(pluginJarFile)) {
    ZipEntry entry = jarFile.getEntry(PLUGIN_XML);
    if (entry == null) {
      return GoPluginDescriptor.usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin);
    }
    try (InputStream pluginXMLStream = jarFile.getInputStream(entry)) {
      return GoPluginDescriptorParser.parseXML(pluginXMLStream, pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin);
    }
  } catch (Exception e) {
    LOGGER.warn("Could not load plugin with jar filename:{}", pluginJarFile.getName(), e);
    String cause = e.getCause() != null ? String.format("%s. Cause: %s", e.getMessage(), e.getCause().getMessage()) : e.getMessage();
    return GoPluginDescriptor.usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin)
        .markAsInvalid(Arrays.asList(String.format("Plugin with ID (%s) is not valid: %s", pluginJarFile.getName(), cause)), e);
  }
}

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

static List<File> matchingFiles( File fileWithRegexInName )
{
  File parent = fileWithRegexInName.getAbsoluteFile().getParentFile();
  if ( parent == null || !parent.exists() )
  {
    throw new IllegalArgumentException( "Directory of " + fileWithRegexInName + " doesn't exist" );
  }
  final Pattern pattern = Pattern.compile( fileWithRegexInName.getName() );
  List<File> files = new ArrayList<>();
  for ( File file : parent.listFiles() )
  {
    if ( pattern.matcher( file.getName() ).matches() )
    {
      files.add( file );
    }
  }
  return files;
}

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

public GraphDatabaseService newImpermanentDatabase( File storeDir )
{
  File absoluteDirectory = storeDir.getAbsoluteFile();
  GraphDatabaseBuilder databaseBuilder = newImpermanentDatabaseBuilder( absoluteDirectory );
  databaseBuilder.setConfig( GraphDatabaseSettings.active_database, absoluteDirectory.getName() );
  databaseBuilder.setConfig( GraphDatabaseSettings.databases_root_path, absoluteDirectory.getParentFile().getAbsolutePath() );
  return databaseBuilder.newGraphDatabase();
}

代码示例来源:origin: prestodb/presto

@Override
public void loadConfigurationManager()
    throws Exception
{
  if (RESOURCE_GROUPS_CONFIGURATION.exists()) {
    Map<String, String> properties = new HashMap<>(loadProperties(RESOURCE_GROUPS_CONFIGURATION));
    String configurationManagerName = properties.remove(CONFIGURATION_MANAGER_PROPERTY_NAME);
    checkArgument(!isNullOrEmpty(configurationManagerName),
        "Resource groups configuration %s does not contain %s", RESOURCE_GROUPS_CONFIGURATION.getAbsoluteFile(), CONFIGURATION_MANAGER_PROPERTY_NAME);
    setConfigurationManager(configurationManagerName, properties);
  }
}

代码示例来源:origin: skylot/jadx

if (!deobfMapFile.exists()) {
  return;
LOG.info("Loading obfuscation map from: {}", deobfMapFile.getAbsoluteFile());
try {
  List<String> lines = FileUtils.readLines(deobfMapFile, MAP_FILE_CHARSET);
  LOG.error("Failed to load deobfuscation map file '{}'", deobfMapFile.getAbsolutePath(), e);

代码示例来源:origin: kiegroup/optaplanner

private void writeTestFile(File file) {
  File parent = file.getAbsoluteFile().getParentFile();
  if (!parent.exists()) {
    if (!parent.mkdirs()) {
      logger.warn("Couldn't create directory: {}", parent);
    }
  }
  try (FileOutputStream fos = new FileOutputStream(file);
      OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8.name())) {
    osw.append(sb);
  } catch (FileNotFoundException e) {
    logger.error("Failed to open test file ({}).", file, e);
  } catch (UnsupportedEncodingException e) {
    logger.error("Failed to open writer.", e);
  } catch (IOException e) {
    logger.error("Failed to write test file ({}).", file, e);
  }
}

代码示例来源:origin: Tencent/tinker

private void unzipApkFile(File file, File destFile) throws TinkerPatchException, IOException {
  String apkName = file.getName();
  if (!apkName.endsWith(TypedValue.FILE_APK)) {
    throw new TinkerPatchException(
      String.format("input apk file path must end with .apk, yours %s\n", apkName)
    );
  }
  String destPath = destFile.getAbsolutePath();
  Logger.d("UnZipping apk to %s", destPath);
  FileOperation.unZipAPk(file.getAbsoluteFile().getAbsolutePath(), destPath);
}

代码示例来源:origin: apache/incubator-druid

private void initCompletedTasks()
{
 File completedTaskDir = getCompletedTaskDir();
 log.info("Looking for any previously completed tasks on disk[%s].", completedTaskDir);
 completedTaskDir.mkdirs();
 if (!completedTaskDir.isDirectory()) {
  throw new ISE("Completed Tasks Dir [%s] does not exist/not-a-directory.", completedTaskDir);
 }
 for (File taskFile : completedTaskDir.listFiles()) {
  try {
   String taskId = taskFile.getName();
   TaskAnnouncement taskAnnouncement = jsonMapper.readValue(taskFile, TaskAnnouncement.class);
   if (taskId.equals(taskAnnouncement.getTaskId())) {
    completedTasks.put(taskId, taskAnnouncement);
    log.info("Found completed task[%s] with status[%s].", taskId, taskAnnouncement.getStatus());
   } else {
    throw new ISE("Corrupted completed task on disk[%s].", taskFile.getAbsoluteFile());
   }
  }
  catch (IOException ex) {
   throw new ISE(ex, "Failed to read completed task from disk at [%s]. Ignored.", taskFile.getAbsoluteFile());
  }
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void requestSQRestart_updates_shareMemory_file() throws IOException {
 File tmpDir = temp.newFolder().getAbsoluteFile();
 settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath());
 settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER);
 ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings.asConfig());
 underTest.requestSQRestart();
 try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(tmpDir, PROCESS_NUMBER)) {
  assertThat(processCommands.askedForRestart()).isTrue();
 }
}

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

private String getAbsoluteName() {
  File f = getAbsoluteFile();
  String name = f.getPath();
  if (f.isDirectory() && name.charAt(name.length() - 1) != separatorChar) {
    // Directories must end with a slash
    name = name + "/";
  }
  if (separatorChar != '/') { // Must convert slashes.
    name = name.replace(separatorChar, '/');
  }
  return name;
}

代码示例来源:origin: jenkinsci/jenkins

@Override
    public OutputStream invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
      f = f.getAbsoluteFile();
      mkdirs(f.getParentFile());
      return new RemoteOutputStream(Files.newOutputStream(fileToPath(writing(f))));
    }
}

代码示例来源:origin: org.reflections/reflections

public static File prepareFile(String filename) {
  File file = new File(filename);
  File parent = file.getAbsoluteFile().getParentFile();
  if (!parent.exists()) {
    //noinspection ResultOfMethodCallIgnored
    parent.mkdirs();
  }
  return file;
}

代码示例来源:origin: android-hacker/VirtualXposed

public static boolean isSymlink(File file) throws IOException {
  if (file == null)
    throw new NullPointerException("File must not be null");
  File canon;
  if (file.getParent() == null) {
    canon = file;
  } else {
    File canonDir = file.getParentFile().getCanonicalFile();
    canon = new File(canonDir, file.getName());
  }
  return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}

相关文章