本文整理了Java中java.io.File.isDirectory()
方法的一些代码示例,展示了File.isDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.isDirectory()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:isDirectory
[英]Indicates if this file represents a directory on the underlying file system.
[中]指示此文件是否表示基础文件系统上的目录。
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 f = new File(filePathString);
if(f.exists() && !f.isDirectory()) {
// do something
}
代码示例来源:origin: libgdx/libgdx
@Override
public boolean accept (File f, String s) {
return (new File(f, s).isDirectory());
}
}
代码示例来源:origin: androidannotations/androidannotations
@Override
public boolean accept(File f) {
return f.exists() && f.isDirectory();
}
};
代码示例来源: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: libgdx/libgdx
static private boolean deleteDirectory (File file) {
if (file.exists()) {
File[] files = file.listFiles();
if (files != null) {
for (int i = 0, n = files.length; i < n; i++) {
if (files[i].isDirectory())
deleteDirectory(files[i]);
else
files[i].delete();
}
}
}
return file.delete();
}
代码示例来源:origin: org.testng/testng
private void addOutputDir(List<String> argv) {
if (null != m_outputDir) {
if (!m_outputDir.exists()) {
m_outputDir.mkdirs();
}
if (m_outputDir.isDirectory()) {
argv.add(CommandLineArgs.OUTPUT_DIRECTORY);
argv.add(m_outputDir.getAbsolutePath());
} else {
throw new BuildException("Output directory is not a directory: " + m_outputDir);
}
}
}
代码示例来源:origin: apache/flink
@VisibleForTesting
static File generateStagingTempFilePath(File targetFile) {
checkArgument(targetFile.isAbsolute(), "targetFile must be absolute");
checkArgument(!targetFile.isDirectory(), "targetFile must not be a directory");
final File parent = targetFile.getParentFile();
final String name = targetFile.getName();
checkArgument(parent != null, "targetFile must not be the root directory");
while (true) {
File candidate = new File(parent, "." + name + ".inprogress." + UUID.randomUUID().toString());
if (!candidate.exists()) {
return candidate;
}
}
}
}
代码示例来源:origin: apache/storm
private static void validateCreateOutputDir(File dir) {
if (!dir.exists()) {
dir.mkdirs();
}
if (!dir.canWrite()) {
throw new IllegalStateException(dir.getName() + " does not have write permissions.");
}
if (!dir.isDirectory()) {
throw new IllegalStateException(dir.getName() + " is not a directory.");
}
}
代码示例来源:origin: redisson/redisson
/**
* Creates a new iterator representation for all files within a folder.
*
* @param folder The root folder.
*/
protected FolderIterator(File folder) {
files = new LinkedList<File>(Collections.singleton(folder));
File candidate;
do {
candidate = files.removeFirst();
File[] file = candidate.listFiles();
if (file != null) {
files.addAll(0, Arrays.asList(file));
}
} while (!files.isEmpty() && (files.peek().isDirectory() || files.peek().equals(new File(folder, JarFile.MANIFEST_NAME))));
}
代码示例来源:origin: gocd/gocd
private void setUpApplicationSupport() throws IOException {
File applicationSupport = new File(APPLICATION_SUPPORT_PATHNAME);
applicationSupport.mkdirs();
if (!applicationSupport.isDirectory()) {
throw new IOException(
"Could not create folder " + APPLICATION_SUPPORT_PATHNAME +
". Please check the permission settings for folder " + applicationSupport.getParentFile().getAbsolutePath());
}
}
代码示例来源:origin: lets-blade/blade
/**
* Filter the file rules
*
* @param file
* @param recursive
* @return
*/
private File[] accept(File file, final boolean recursive) {
// Custom filtering rules If you can loop (include subdirectories) or is the end of the file. Class (compiled java class file)
return file.listFiles(file1 -> (recursive && file1.isDirectory()) || (file1.getName().endsWith(".class")));
}
代码示例来源:origin: prestodb/presto
private URLClassLoader buildClassLoader(String plugin)
throws Exception
{
File file = new File(plugin);
if (file.isFile() && (file.getName().equals("pom.xml") || file.getName().endsWith(".pom"))) {
return buildClassLoaderFromPom(file);
}
if (file.isDirectory()) {
return buildClassLoaderFromDirectory(file);
}
return buildClassLoaderFromCoordinates(plugin);
}
代码示例来源: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: google/guava
private static Iterable<File> fileTreeChildren(File file) {
// check isDirectory() just because it may be faster than listFiles() on a non-directory
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null) {
return Collections.unmodifiableList(Arrays.asList(files));
}
}
return Collections.emptyList();
}
代码示例来源: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: jenkinsci/jenkins
@Override
public boolean accept(File pathname) {
return pathname.isDirectory() && !existing.contains(pathname.getName());
}
})) {
代码示例来源:origin: stackoverflow.com
public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
}
}
}
final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);
代码示例来源:origin: stackoverflow.com
File f = new File("/Path/To/File/or/Directory");
if (f.exists() && f.isDirectory()) {
...
}
代码示例来源:origin: libgdx/libgdx
static private boolean deleteDirectory (File file) {
if (file.exists()) {
File[] files = file.listFiles();
if (files != null) {
for (int i = 0, n = files.length; i < n; i++) {
if (files[i].isDirectory())
deleteDirectory(files[i]);
else
files[i].delete();
}
}
}
return file.delete();
}
内容来源于网络,如有侵权,请联系作者删除!