congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
File.isFile
Code IndexAdd Tabnine to your IDE (free)

How to use
isFile
method
in
java.io.File

Best Java code snippets using java.io.File.isFile (Showing top 20 results out of 46,503)

Refine searchRefine arrow

  • File.<init>
  • File.exists
  • File.isDirectory
  • File.getName
  • File.listFiles
  • File.getAbsolutePath
canonical example by Tabnine

public long getDirectorySize(File file) {
 if (!file.exists()) {
  return 0;
 }
 if (file.isFile()) {
  return file.length();
 }
 File[] files;
 if (!file.isDirectory() || (files = file.listFiles()) == null) {
  return 0;
 }
 return Arrays.stream(files).mapToLong(f -> getDirectorySize(f)).sum();
}
origin: stackoverflow.com

 File folder = new File("your/path");
File[] listOfFiles = folder.listFiles();

  for (int i = 0; i < listOfFiles.length; i++) {
   if (listOfFiles[i].isFile()) {
    System.out.println("File " + listOfFiles[i].getName());
   } else if (listOfFiles[i].isDirectory()) {
    System.out.println("Directory " + listOfFiles[i].getName());
   }
  }
origin: redisson/redisson

  public int compare(File file1, File file2) {
    if (file1.isFile() && file2.isDirectory()) {
      return order;
    }
    if (file1.isDirectory() && file2.isFile()) {
      return -order;
    }
    return 0;
  }
}
origin: redisson/redisson

/**
 * Returns <code>true</code> if file exists.
 */
public static boolean isExistingFile(File file) {
  if (file == null) {
    return false;
  }
  return file.exists() && file.isFile();
}
origin: hankcs/HanLP

  /**
   * 本地文件是否存在
   * @param path
   * @return
   */
  public static boolean isFileExisted(String path)
  {
    File file = new File(path);
    return file.isFile() && file.exists();
  }
}
origin: eclipse-vertx/vert.x

private File getJava() {
 File java;
 File home = new File(System.getProperty("java.home"));
 if (ExecUtils.isWindows()) {
  java = new File(home, "bin/java.exe");
 } else {
  java = new File(home, "bin/java");
 }
 if (!java.isFile()) {
  out.println("Cannot find java executable - " + java.getAbsolutePath() + " does not exist");
  ExecUtils.exitBecauseOfSystemConfigurationIssue();
 }
 return java;
}
origin: oracle/opengrok

@Override
boolean isRepositoryFor(File file, boolean interactive) {
  if (file.isDirectory()) {
    File f = new File(file, MYSCMSERVERINFO_FILE);
    return f.exists() && f.isFile();
  }
  return false;
}
origin: gocd/gocd

@Test
public void shouldZipFileAndUnzipIt() throws IOException {
  zipFile = zipUtil.zip(srcDir, temporaryFolder.newFile(), Deflater.NO_COMPRESSION);
  assertThat(zipFile.isFile(), is(true));
  zipUtil.unzip(zipFile, destDir);
  File baseDir = new File(destDir, srcDir.getName());
  assertIsDirectory(new File(baseDir, emptyDir.getName()));
  assertIsDirectory(new File(baseDir, childDir1.getName()));
  File actual1 = new File(baseDir, file1.getName());
  assertThat(actual1.isFile(), is(true));
  assertThat(fileContent(actual1), is(fileContent(file1)));
  File actual2 = new File(baseDir, childDir1.getName() + File.separator + file2.getName());
  assertThat(actual2.isFile(), is(true));
  assertThat(fileContent(actual2), is(fileContent(file2)));
}
origin: Tencent/tinker

public static final boolean deleteDir(File file) {
  if (file == null || (!file.exists())) {
    return false;
  }
  if (file.isFile()) {
    file.delete();
  } else if (file.isDirectory()) {
    File[] files = file.listFiles();
    for (int i = 0; i < files.length; i++) {
      deleteDir(files[i]);
    }
  }
  file.delete();
  return true;
}
origin: jenkinsci/jenkins

/**
 * Returns the log file.
 * @return The file may reference both uncompressed or compressed logs
 */  
public @Nonnull File getLogFile() {
  File rawF = new File(getRootDir(), "log");
  if (rawF.isFile()) {
    return rawF;
  }
  File gzF = new File(getRootDir(), "log.gz");
  if (gzF.isFile()) {
    return gzF;
  }
  //If both fail, return the standard, uncompressed log file
  return rawF;
}
origin: libgdx/libgdx

/** Processes the specified input file or directory.
 * @param outputRoot May be null if there is no output from processing the files.
 * @return the processed files added with {@link #addProcessedFile(Entry)}. */
public ArrayList<Entry> process (File inputFileOrDir, File outputRoot) throws Exception {
  if (!inputFileOrDir.exists())
    throw new IllegalArgumentException("Input file does not exist: " + inputFileOrDir.getAbsolutePath());
  if (inputFileOrDir.isFile())
    return process(new File[] {inputFileOrDir}, outputRoot);
  else
    return process(inputFileOrDir.listFiles(), outputRoot);
}
origin: spockframework/spock

/**
 * Returns the class file for the given class (which has been verified to exist in the returned location),
 * or null if the class file could not be found (e.g. because it is contained in a Jar).
 */
public static File getClassFile(Class<?> clazz) {
 File dir = new File(clazz.getProtectionDomain().getCodeSource().getLocation().getPath());
 if (!dir.isDirectory()) return null; // class file might be contained in Jar
 File clazzFile = new File(dir, clazz.getName().replace('.', File.separatorChar) + ".class");
 return clazzFile.isFile() ? clazzFile : null;
}
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: eclipse-vertx/vert.x

private static List<JavaFileObject> browseDir(String packageName, File directory) {
 List<JavaFileObject> result = new ArrayList<>();
 for (File childFile : directory.listFiles()) {
  if (childFile.isFile() && childFile.getName().endsWith(CLASS_FILE)) {
   String binaryName = packageName + "." + childFile.getName().replaceAll(CLASS_FILE + "$", "");
   result.add(new CustomJavaFileObject(childFile.toURI(), JavaFileObject.Kind.CLASS, binaryName));
  }
 }
 return result;
}
origin: apache/storm

  private void checkFilesExist(Collection<File> dependencies) {
    for (File dependency : dependencies) {
      if (!dependency.isFile() || !dependency.exists()) {
        throw new FileNotAvailableException(dependency.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: gocd/gocd

  public int compare(File file1, File file2) {
    if (file1.isDirectory() && file2.isDirectory() || file1.isFile() && file2.isFile()) {
      return file1.getName().compareTo(file2.getName());
    } else {
      return file1.isDirectory() ? -1 : 1;
    }
  }
}
origin: apache/incubator-druid

 @Override
 public boolean accept(File pathname)
 {
  return pathname.exists()
      && pathname.isFile()
      && (pattern == null || pattern.matcher(pathname.getName()).matches());
 }
}
origin: hankcs/HanLP

  @Override
  public boolean accept(File pathname)
  {
    return pathname.isFile() && pathname.getName().endsWith(".txt");
  }
});
origin: querydsl/querydsl

public static void delete(File file) throws IOException {
  if (file.isDirectory()) {
    for (File f : file.listFiles()) {
      delete(f);
    }
  }
  if (file.isDirectory() || file.isFile()) {
    if (!file.delete()) {
      throw new IllegalStateException("Deletion of " + file.getPath() + " failed");
    }
  }
}
java.ioFileisFile

Javadoc

Indicates if this file represents a file on the underlying file system.

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

  • Making http post requests using okhttp
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • addToBackStack (FragmentTransaction)
  • findViewById (Activity)
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Permission (java.security)
    Legacy security code; do not use.
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top plugins for WebStorm
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