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

How to use
getParentFile
method
in
java.io.File

Best Java code snippets using java.io.File.getParentFile (Showing top 20 results out of 57,006)

Refine searchRefine arrow

  • File.<init>
  • File.exists
  • File.mkdirs
  • File.getName
  • FileOutputStream.<init>
  • File.getAbsolutePath
origin: Tencent/tinker

public InfoWriter(Configuration config, String infoPath) throws IOException {
  this.config = config;
  this.infoPath = infoPath;
  if (infoPath != null) {
    this.infoFile = new File(infoPath);
    if (!infoFile.getParentFile().exists()) {
      infoFile.getParentFile().mkdirs();
    }
  } else {
    this.infoFile = null;
  }
}
origin: jenkinsci/jenkins

public CompressedFile(File file) {
  this.file = file;
  this.gz = new File(file.getParentFile(),file.getName()+".gz");
}
origin: Tencent/tinker

public static void ensureFileDirectory(File file) {
  if (file == null) {
    return;
  }
  File parentFile = file.getParentFile();
  if (!parentFile.exists()) {
    parentFile.mkdirs();
  }
}
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: libgdx/libgdx

public FileHandle parent () {
  File parent = file.getParentFile();
  if (parent == null) {
    if (type == FileType.Absolute)
      parent = new File("/");
    else
      parent = new File("");
  }
  return new HeadlessFileHandle(parent, type);
}
origin: jenkinsci/jenkins

private static void parseClassPath(Manifest manifest, File archive, List<File> paths, String attributeName, String separator) throws IOException {
  String classPath = manifest.getMainAttributes().getValue(attributeName);
  if(classPath==null) return; // attribute not found
  for (String s : classPath.split(separator)) {
    File file = resolve(archive, s);
    if(file.getName().contains("*")) {
      // handle wildcard
      FileSet fs = new FileSet();
      File dir = file.getParentFile();
      fs.setDir(dir);
      fs.setIncludes(file.getName());
      for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) {
        paths.add(new File(dir,included));
      }
    } else {
      if(!file.exists())
        throw new IOException("No such file: "+file);
      paths.add(file);
    }
  }
}
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: stackoverflow.com

 File file = new File("C:\\user\\Desktop\\dir1\\dir2\\filename.txt");
file.getParentFile().mkdirs();
FileWriter writer = new FileWriter(file);
origin: jenkinsci/jenkins

@Override
public void visit(File f, String relativePath) throws IOException {
  if (f.isFile()) {
    File target = new File(dest, relativePath);
    mkdirsE(target.getParentFile());
    Path targetPath = fileToPath(writing(target));
    exceptionEncountered = exceptionEncountered || !tryCopyWithAttributes(f, targetPath);
    if (exceptionEncountered) {
      Files.copy(fileToPath(f), targetPath, StandardCopyOption.REPLACE_EXISTING);
      if (!logMessageShown) {
        LOGGER.log(Level.INFO, 
          "JENKINS-52325: Jenkins failed to retain attributes when copying to {0}, so proceeding without attributes.", 
          dest.getAbsolutePath());
        logMessageShown = true;
      }
    }
    count.incrementAndGet();
  }
}
private boolean tryCopyWithAttributes(File f, Path targetPath) {
origin: commons-io/commons-io

void openOutputStream_noParent(final boolean createFile) throws Exception {
  final File file = new File("test.txt");
  assertNull(file.getParentFile());
  try {
    if (createFile) {
      TestUtils.createLineBasedFile(file, new String[]{"Hello"});
    }
    try (FileOutputStream out = FileUtils.openOutputStream(file)) {
      out.write(0);
    }
    assertTrue(file.exists());
  } finally {
    if (!file.delete()) {
      file.deleteOnExit();
    }
  }
}
origin: Blankj/AndroidUtilCode

private static boolean createOrExistsFile(final File file) {
  if (file == null) return false;
  if (file.exists()) return file.isFile();
  if (!createOrExistsDir(file.getParentFile())) return false;
  try {
    return file.createNewFile();
  } catch (IOException e) {
    e.printStackTrace();
    return false;
  }
}
origin: commons-io/commons-io

public static void createLineBasedFile(final File file, final String[] data) throws IOException {
  if (file.getParentFile() != null && !file.getParentFile().exists()) {
    throw new IOException("Cannot create file " + file + " as the parent directory does not exist");
  }
  try (final PrintWriter output = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"))) {
    for (final String element : data) {
      output.println(element);
    }
  }
}
origin: apache/incubator-druid

@Before
public void setUp() throws IOException
{
 testDir = temporaryFolder.newFolder("testDir");
 testFile = new File(testDir, "test.dat");
 try (OutputStream outputStream = new FileOutputStream(testFile)) {
  outputStream.write(StringUtils.toUtf8(content));
 }
 Assert.assertTrue(testFile.getParentFile().equals(testDir));
}
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: jenkinsci/jenkins

  @Override
  public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
    symlinking(f);
    Util.createSymlink(f.getParentFile(), target, f.getName(), listener);
    return null;
  }
}
origin: gocd/gocd

public void streamToFile(InputStream stream, File dest) throws IOException {
  dest.getParentFile().mkdirs();
  FileOutputStream out = new FileOutputStream(dest, true);
  try {
    IOUtils.copyLarge(stream, out);
  } finally {
    IOUtils.closeQuietly(out);
  }
}
origin: jenkinsci/jenkins

public void on() {
  try {
    file.getParentFile().mkdirs();
    Files.newOutputStream(file.toPath()).close();
    get();  // update state
  } catch (IOException | InvalidPathException e) {
    LOGGER.log(Level.WARNING, "Failed to touch "+file);
  }
}
origin: stanfordnlp/CoreNLP

private boolean checkFile(File file) {
 if (file.isFile()) {
  fileChooser.setCurrentDirectory(file.getParentFile());
  return true;
 } else {
  String message = "File Not Found: "+file.getAbsolutePath();
  displayError("File Not Found Error", message);
  return false;
 }
}
origin: org.testng/testng

public static void copyFile(InputStream from, File to) throws IOException {
 if (! to.getParentFile().exists()) {
  to.getParentFile().mkdirs();
 }
 try (OutputStream os = new FileOutputStream(to)) {
  byte[] buffer = new byte[65536];
  int count = from.read(buffer);
  while (count > 0) {
   os.write(buffer, 0, count);
   count = from.read(buffer);
  }
 }
}
origin: libgdx/libgdx

  static public void main (String[] args) throws Exception {
    Settings settings = null;
    String input = null, output = null, packFileName = "pack.atlas";

    switch (args.length) {
    case 4:
      settings = new Json().fromJson(Settings.class, new FileReader(args[3]));
    case 3:
      packFileName = args[2];
    case 2:
      output = args[1];
    case 1:
      input = args[0];
      break;
    default:
      System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]");
      System.exit(0);
    }

    if (output == null) {
      File inputFile = new File(input);
      output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath();
    }
    if (settings == null) settings = new Settings();

    process(settings, input, output, packFileName);
  }
}
java.ioFilegetParentFile

Javadoc

Returns a new file made from the pathname of the parent of this file. This is the path up to but not including the last name. null is returned when there is no parent.

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
  • getPath
    Converts this abstract pathname into a pathname string. The resulting string uses the #separator to
  • 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
  • Github Copilot alternatives
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