Tabnine Logo
File.getPath
Code IndexAdd Tabnine to your IDE (free)

How to use
getPath
method
in
java.io.File

Best Java code snippets using java.io.File.getPath (Showing top 20 results out of 114,327)

Refine searchRefine arrow

  • File.<init>
  • File.exists
  • File.isDirectory
  • File.mkdirs
  • File.getName
  • File.getAbsolutePath
  • FileOutputStream.<init>
origin: libgdx/libgdx

  public File file () {
    if (type == FileType.External) return new File(HeadlessFiles.externalPath, file.getPath());
    if (type == FileType.Local) return new File(HeadlessFiles.localPath, file.getPath());
    return file;
  }
}
origin: jenkinsci/jenkins

    @Override
    public String call() throws IOException {
      File exe = getExeFile("mvn");
      if(exe.exists())
        return exe.getPath();
      exe = getExeFile("maven");
      if(exe.exists())
        return exe.getPath();
      return null;
    }
}
origin: gocd/gocd

  public static String configuration(String warFile) {
    if (new File(warFile).isDirectory()) {
      return new File(warFile, webdefaultXml).getPath();
    }
    return "jar:file:" + warFile + "!/" + webdefaultXml;
  }
}
origin: wildfly/wildfly

protected void createRootDir() {
  root_dir=new File(location);
  if(root_dir.exists()) {
    if(!root_dir.isDirectory())
      throw new IllegalArgumentException("location " + root_dir.getPath() + " is not a directory");
  }
  else
    root_dir.mkdirs();
  if(!root_dir.exists())
    throw new IllegalArgumentException("location " + root_dir.getPath() + " could not be accessed");
}
origin: GitLqr/LQRWeChat

private static String saveBitmap(Bitmap bm, String imageUrlName) {
  File f = new File(SAVEADDRESS, imageUrlName);
  try {
    FileOutputStream out = new FileOutputStream(f);
    bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
    out.flush();
    out.close();
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return SCHEMA + f.getPath();
}
origin: libgdx/libgdx

/** Returns a stream for reading this file as bytes.
 * @throw RuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */
public InputStream read () {
  if (type == FileType.Classpath && !file.exists()) {
    InputStream input = FileDescriptor.class.getResourceAsStream("/" + file.getPath().replace('\\', '/'));
    if (input == null) throw new RuntimeException("File not found: " + file + " (" + type + ")");
    return input;
  }
  try {
    return new FileInputStream(file());
  } catch (FileNotFoundException ex) {
    if (file().isDirectory())
      throw new RuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex);
    throw new RuntimeException("Error reading file: " + file + " (" + type + ")", ex);
  }
}
origin: stackoverflow.com

 import java.io.File;
public class PathTesting {
  public static void main(String [] args) {
    File f = new File("test/.././file.txt");
    System.out.println(f.getPath());
    System.out.println(f.getAbsolutePath());
    try {
      System.out.println(f.getCanonicalPath());
    }
    catch(Exception e) {}
  }
}
origin: iBotPeaches/Apktool

public static void cpdir(File src, File dest) throws BrutException {
  dest.mkdirs();
  File[] files = src.listFiles();
  for (int i = 0; i < files.length; i++) {
    File file = files[i];
    File destFile = new File(dest.getPath() + File.separatorChar
      + file.getName());
    if (file.isDirectory()) {
      cpdir(file, destFile);
      continue;
    }
    try {
      InputStream in = new FileInputStream(file);
      OutputStream out = new FileOutputStream(destFile);
      IOUtils.copy(in, out);
      in.close();
      out.close();
    } catch (IOException ex) {
      throw new BrutException("Could not copy file: " + file, ex);
    }
  }
}
origin: stanfordnlp/CoreNLP

public static SimpleMatrix loadMatrix(String binaryName, String textName) throws IOException {
 File matrixFile = new File(binaryName);
 if (matrixFile.exists()) {
  return SimpleMatrix.loadBinary(matrixFile.getPath());
 }
 matrixFile = new File(textName);
 if (matrixFile.exists()) {
  return NeuralUtils.loadTextMatrix(matrixFile);
 }
 throw new RuntimeException("Could not find either " + binaryName + " or " + textName);
}
origin: stackoverflow.com

 public void restartApplication()
{
 final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
 final File currentJar = new File(MyClassInTheJar.class.getProtectionDomain().getCodeSource().getLocation().toURI());

 /* is it a jar file? */
 if(!currentJar.getName().endsWith(".jar"))
  return;

 /* Build command: java -jar application.jar */
 final ArrayList<String> command = new ArrayList<String>();
 command.add(javaBin);
 command.add("-jar");
 command.add(currentJar.getPath());

 final ProcessBuilder builder = new ProcessBuilder(command);
 builder.start();
 System.exit(0);
}
origin: jenkinsci/jenkins

/**
 * On Windows, jenkins.war is locked, so we place a new version under a special name,
 * which is picked up by the service wrapper upon restart.
 */
@Override
public void rewriteHudsonWar(File by) throws IOException {
  File dest = getHudsonWar();
  // this should be impossible given the canRewriteHudsonWar method,
  // but let's be defensive
  if(dest==null)  throw new IOException("jenkins.war location is not known.");
  // backing up the old jenkins.war before its lost due to upgrading
  // unless we are trying to rewrite jenkins.war by a backup itself
  File bak = new File(dest.getPath() + ".bak");
  if (!by.equals(bak))
    FileUtils.copyFile(dest, bak);
  String baseName = dest.getName();
  baseName = baseName.substring(0,baseName.indexOf('.'));
  File baseDir = getBaseDir();
  File copyFiles = new File(baseDir,baseName+".copies");
  try (FileWriter w = new FileWriter(copyFiles, true)) {
    w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n');
  }
}
origin: libgdx/libgdx

    boolean found = false;
    for (Pattern pattern : inputRegex) {
      if (pattern.matcher(file.getName()).matches()) {
        found = true;
        continue;
  if (inputFilter != null && !inputFilter.accept(dir, file.getName())) continue;
  String outputName = file.getName();
  if (outputSuffix != null) outputName = outputName.replaceAll("(.*)\\..*", "$1") + outputSuffix;
    entry.outputFile = new File(outputRoot, outputName);
  } else {
    entry.outputFile = new File(outputDir, outputName);
if (recursive && file.isDirectory()) {
  File subdir = outputDir.getPath().length() == 0 ? new File(file.getName()) : new File(outputDir, file.getName());
  process(file.listFiles(inputFilter), outputRoot, subdir, dirToEntries, depth + 1);
origin: stackoverflow.com

 // Prepare source somehow.
String source = "package test; public class Test { static { System.out.println(\"hello\"); } public Test() { System.out.println(\"world\"); } }";

// Save source in .java file.
File root = new File("/java"); // On Windows running on C:\, this is C:\java.
File sourceFile = new File(root, "test/Test.java");
sourceFile.getParentFile().mkdirs();
Files.write(sourceFile.toPath(), source.getBytes(StandardCharsets.UTF_8));

// Compile source file.
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
compiler.run(null, null, null, sourceFile.getPath());

// Load and instantiate compiled class.
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
Class<?> cls = Class.forName("test.Test", true, classLoader); // Should print "hello".
Object instance = cls.newInstance(); // Should print "world".
System.out.println(instance); // Should print "test.Test@hashcode".
origin: neo4j/neo4j

private static void mockFiles( String[] filenames, ArrayList<File> files, boolean isDirectories )
{
  for ( String filename : filenames )
  {
    File file = mock( File.class );
    String[] fileNameParts = filename.split( "/" );
    when( file.getName() ).thenReturn( fileNameParts[fileNameParts.length - 1] );
    when( file.isFile() ).thenReturn( !isDirectories );
    when( file.isDirectory() ).thenReturn( isDirectories );
    when( file.exists() ).thenReturn( true );
    when( file.getPath() ).thenReturn( filename );
    files.add( file );
  }
}
origin: lets-blade/blade

@Override
public void download(@NonNull String fileName, @NonNull File file) throws Exception {
  if (!file.exists() || !file.isFile()) {
    throw new NotFoundException("Not found file: " + file.getPath());
  }
  String contentType = StringKit.mimeType(file.getName());
  headers.put("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes("UTF-8"), "ISO8859_1"));
  headers.put(HttpConst.CONTENT_LENGTH.toString(), String.valueOf(file.length()));
  headers.put(HttpConst.CONTENT_TYPE_STRING, contentType);
  this.body = new StreamBody(new FileInputStream(file));
}
origin: javamelody/javamelody

private static void mkdirs(File directory) {
  if (!directory.exists() && !directory.mkdirs()) {
    throw new IllegalStateException("Can't create directory " + directory.getPath());
  }
}
origin: SonarSource/sonarqube

@Override
public FilePredicate is(File ioFile) {
 if (ioFile.isAbsolute()) {
  return hasAbsolutePath(ioFile.getAbsolutePath());
 }
 return hasRelativePath(ioFile.getPath());
}
origin: stanfordnlp/CoreNLP

private Tree primeNextTree() {
 Tree t = null;
 try {
  t = tr.readTree();
  if(t == null && primeNextFile()) //Current file is exhausted
   t = tr.readTree();
  //Associate this tree with a file and line number
  if(t != null && t.label() != null && t.label() instanceof HasIndex) {
   HasIndex lab = (HasIndex) t.label();
   lab.setSentIndex(curLineId++);
   lab.setDocID(currentFile.getName());
  }
 } catch (IOException e) {
  System.err.printf("%s: Error reading from file %s:%n%s%n", this.getClass().getName(), currentFile.getPath(), e.toString());
  throw new RuntimeException(e);
 }
 return t;
}
origin: jenkinsci/jenkins

/**
 * Checks if the home directory is valid.
 * @since 1.563
 */
public FormValidation doCheckHome(@QueryParameter File value) {
  // this can be used to check the existence of a file on the server, so needs to be protected
  Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
  if (value.getPath().isEmpty()) {
    return FormValidation.ok();
  }
  if (!value.isDirectory()) {
    return FormValidation.warning(Messages.ToolDescriptor_NotADirectory(value));
  }
  return checkHomeDirectory(value);
}
origin: wildfly/wildfly

protected void createDiskCacheFile() throws IOException {
  root_dir=new File(this.cache_dir);
  if(root_dir.exists()) {
    if(!root_dir.isDirectory())
      throw new IllegalArgumentException("location " + root_dir.getPath() + " is not a directory");
  }
  else {
    root_dir.mkdirs();
  }
  if(!root_dir.exists())
    throw new IllegalArgumentException("location " + root_dir.getPath() + " could not be accessed");
  filter=(dir, name1) -> name1.endsWith(SUFFIX);
}
java.ioFilegetPath

Javadoc

Returns the path of this file.

Popular methods of File

  • <init>
    Creates a new File instance by converting the givenfile: URI into an abstract pathname. The exact fo
  • exists
    Tests whether the file or directory denoted by this abstract pathname exists.
  • getAbsolutePath
    Returns the absolute pathname string of this abstract pathname. If this abstract pathname is already
  • getName
    Returns the name of the file or directory denoted by this abstract pathname. This is just the last n
  • isDirectory
  • mkdirs
  • delete
    Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a director
  • listFiles
    Returns an array of abstract pathnames denoting the files and directories in the directory denoted b
  • getParentFile
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
  • isFile
  • length
    Returns the length of the file denoted by this abstract pathname. The return value is unspecified if
  • toURI
  • length,
  • toURI,
  • createTempFile,
  • createNewFile,
  • toPath,
  • mkdir,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • runOnUiThread (Activity)
  • getSharedPreferences (Context)
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • BoxLayout (javax.swing)
  • JButton (javax.swing)
  • JCheckBox (javax.swing)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now