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

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

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

File.getAbsolutePath介绍

[英]Returns the absolute path of this file. An absolute path is a path that starts at a root of the file system. On Android, there is only one root: /.

A common use for absolute paths is when passing paths to a Process as command-line arguments, to remove the requirement implied by relative paths, that the child must have the same working directory as its parent.
[中]返回此文件的绝对路径。绝对路径是从文件系统的根开始的路径。在Android上,只有一个根:/。
绝对路径的一个常见用法是将路径作为命令行参数传递给进程,以消除相对路径所隐含的要求,即子进程必须具有与其父进程相同的工作目录。

代码示例

代码示例来源:origin: stackoverflow.com

File imgFile = new  File("/sdcard/Images/test_image.jpg");

if(imgFile.exists()){

  Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

  ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);

  myImage.setImageBitmap(myBitmap);

}

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

private InputFile(File file) throws IOException {
  if (!file.exists()) {
    throw new IOException("File not found: " + file.getAbsolutePath());
  }
  this.file = file;
}

代码示例来源:origin: stackoverflow.com

System.out.println(new File(".").getAbsolutePath());

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

/**
 * @param filePath the file path to be validated
 * @return Returns null if valid otherwise error message
 */
public static String validateFileInput(String filePath) {
  File file = new File(filePath);
  if (!file.exists()) {
    return "File '" + file.getAbsolutePath() + "' does not exist.";
  }
  if (!file.canRead()) {
    return "Read permission is denied on the file '" + file.getAbsolutePath() + "'";
  }
  if (file.isDirectory()) {
    return "'" + file.getAbsolutePath() + "' is a direcory. it must be a file.";
  }
  return null;
}

代码示例来源:origin: stackoverflow.com

// Assume block needs to be inside a Try/Catch block.
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
Integer counter = 0;
File file = new File(path, "FitnessGirl"+counter+".jpg"); // the File to save , append increasing numeric counter to prevent files from getting overwritten.
fOut = new FileOutputStream(file);

Bitmap pictureBitmap = getImageBitmap(myurl); // obtaining the Bitmap
pictureBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate
fOut.flush(); // Not really required
fOut.close(); // do not forget to close the stream

MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());

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

private static void setRunningLocation(CliMain m) {
  mRunningLocation = m.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
  try {
    mRunningLocation = URLDecoder.decode(mRunningLocation, "utf-8");
  } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
  }
  if (mRunningLocation.endsWith(".jar")) {
    mRunningLocation = mRunningLocation.substring(0, mRunningLocation.lastIndexOf(File.separator) + 1);
  }
  File f = new File(mRunningLocation);
  mRunningLocation = f.getAbsolutePath();
}

代码示例来源:origin: stackoverflow.com

File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, "filename");

FileOutputStream f = new FileOutputStream(file);
...

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

@Override
  File ensureDirectoryExists( FileSystemAbstraction fileSystem, File dir )
  {
    if ( !dir.exists() && !dir.mkdirs() )
    {
      String message = String.format( "Unable to create directory path[%s] for Neo4j store" + ".",
          dir.getAbsolutePath() );
      throw new RuntimeException( message );
    }
    return dir;
  }
},

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

private static void checkFile(File file) {
  if (!file.exists()) {
    throw new JadxArgsValidateException("File not found " + file.getAbsolutePath());
  }
  if (file.isDirectory()) {
    throw new JadxArgsValidateException("Expected file but found directory instead: " + file.getAbsolutePath());
  }
}

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

/**
 * Compresses a file into gzip archive.
 */
public static File gzip(File file) throws IOException {
  if (file.isDirectory()) {
    throw new IOException("Can't gzip folder");
  }
  FileInputStream fis = new FileInputStream(file);
  String gzipName = file.getAbsolutePath() + GZIP_EXT;
  GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(gzipName));
  try {
    StreamUtil.copy(fis, gzos);
  } finally {
    StreamUtil.close(gzos);
    StreamUtil.close(fis);
  }
  return new File(gzipName);
}

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

protected static void deleteRecursively(File f) throws IOException {
  if (f.isDirectory()) {
    FileUtils.deleteDirectory(f);
  } else if (!f.delete()) {
    System.err.println("Failed to delete file " + f.getAbsolutePath());
  }
}

代码示例来源: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: Tencent/tinker

/**
 * @param output unsigned apk file output
 * @throws IOException
 */
private void generateUnsignedApk(File output) throws IOException {
  Logger.d("Generate unsigned apk: %s", output.getName());
  final File tempOutDir = config.mTempResultDir;
  if (!tempOutDir.exists()) {
    throw new IOException(String.format(
      "Missing patch unzip files, path=%s\n", tempOutDir.getAbsolutePath()));
  }
  FileOperation.zipInputDir(tempOutDir, output, null);
  if (!output.exists()) {
    throw new IOException(String.format(
      "can not found the unsigned apk file path=%s",
      output.getAbsolutePath()));
  }
}

代码示例来源:origin: hs-web/hsweb-framework

public static FileInfo from(File file) {
    FileInfo info = new FileInfo();
    info.setName(file.getName());
    info.setLength(file.length());
    info.setParent(file.getParent());
    info.setAbsolutePath(file.getAbsolutePath());
    info.setFile(file.isFile());
    info.setDir(file.isDirectory());
    return info;
  }
}

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

/**
 * Scans single path.
 */
protected void scanPath(File file) {
  String path = file.getAbsolutePath();
  if (StringUtil.endsWithIgnoreCase(path, JAR_FILE_EXT)) {
    if (!acceptJar(file)) {
      return;
    }
    scanJarFile(file);
  } else if (file.isDirectory()) {
    scanClassPath(file);
  }
}

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

private void copyAndReplace (String outputDir, Project project, Map<String, String> values) {
  File out = new File(outputDir);
  if (!out.exists() && !out.mkdirs()) {
    throw new RuntimeException("Couldn't create output directory '" + out.getAbsolutePath() + "'");
  }
  for (ProjectFile file : project.files) {
    copyFile(file, out, values);
  }
}

代码示例来源:origin: iBotPeaches/Apktool

public static String getAaptExecutionCommand(String aaptPath, File aapt) throws BrutException {
  if (! aaptPath.isEmpty()) {
    File aaptFile = new File(aaptPath);
    if (aaptFile.canRead() && aaptFile.exists()) {
      aaptFile.setExecutable(true);
      return aaptFile.getPath();
    } else {
      throw new BrutException("binary could not be read: " + aaptFile.getAbsolutePath());
    }
  } else {
    return aapt.getAbsolutePath();
  }
}

代码示例来源:origin: stackoverflow.com

File f = new File("C:\\Hello\\AnotherFolder\\The File Name.PDF");  
System.out.println(f.getAbsolutePath().substring(f.getAbsolutePath().lastIndexOf("\\")+1));

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

public static boolean isSymbolicLink(File parent, String name)
    throws IOException {
  if (parent == null) {
    File f = new File(name);
    parent = f.getParentFile();
    name = f.getName();
  }
  File toTest = new File(parent.getCanonicalPath(), name);
  return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath());
}

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

private File resolveLogFileInSpecifiedPath(String logFile) throws FileNotFoundException {
  File outputDirectory = FileHelper.resolveOutputDirectory(processingEnv);
  logFile = logFile.replace("{outputFolder}", outputDirectory.getAbsolutePath());
  return new File(logFile);
}

相关文章

微信公众号

最新文章

更多