Java Code Examples for java.io.File#isFile()
The following examples show how to use
java.io.File#isFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModulesRestarter.java From InviZible with GNU General Public License v3.0 | 6 votes |
private String readPidFile(Context context, String path) { String pid = ""; File file = new File(path); if (file.isFile()) { List<String> lines = FileOperations.readTextFileSynchronous(context, path); for (String line : lines) { if (!line.trim().isEmpty()) { pid = line.trim(); break; } } } return pid; }
Example 2
Source File: FileUtils.java From Android-utils with Apache License 2.0 | 6 votes |
public static boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter) { if (dir == null) return false; // dir doesn't exist then return true if (!dir.exists()) return true; // dir isn't a directory then return false if (!dir.isDirectory()) return false; File[] files = dir.listFiles(); if (files != null && files.length != 0) { for (File file : files) { if (filter.accept(file)) { if (file.isFile()) { if (!file.delete()) return false; } else if (file.isDirectory()) { if (!deleteDir(file)) return false; } } } } return true; }
Example 3
Source File: ParserServletContext.java From netbeans with Apache License 2.0 | 6 votes |
/** * Return the set of resource paths for the "directory" at the * specified context path. * * @param path Context-relative base path */ public Set<String> getResourcePaths(String path) { LOGGER.log(Level.FINE, "getResourcePaths({0})", path); Set<String> thePaths = new HashSet<String>(); if (!path.endsWith("/")) path += "/"; String basePath = getRealPath(path); if (basePath == null) return (thePaths); File theBaseDir = new File(basePath); if (!theBaseDir.exists() || !theBaseDir.isDirectory()) return (thePaths); String theFiles[] = theBaseDir.list(); for (int i = 0; i < theFiles.length; i++) { File testFile = new File(basePath + File.separator + theFiles[i]); if (testFile.isFile()) thePaths.add(path + theFiles[i]); else if (testFile.isDirectory()) thePaths.add(path + theFiles[i] + "/"); } return thePaths; }
Example 4
Source File: ComponentServiceImpl.java From primecloud-controller with GNU General Public License v2.0 | 6 votes |
private void deleteDirectoryAndFile(File delFile) { if (delFile == null || !delFile.exists()) { return; } if (delFile.isFile()) { // ファイル削除 if (delFile.exists() && !delFile.delete()) { delFile.deleteOnExit(); } } else { // ディレクトリの場合、再帰する File[] list = delFile.listFiles(); for (int i = 0; i < list.length; i++) { deleteDirectoryAndFile(list[i]); } if (delFile.exists() && !delFile.delete()) { delFile.deleteOnExit(); } } }
Example 5
Source File: SQRBuildService.java From TeamCity.SonarQubePlugin with Apache License 2.0 | 6 votes |
@NotNull private String getExecutablePath() throws RunBuildException { final String path = getSonarScannerRoot(); final String execName = myOsType == WINDOWS ? "sonar-runner.bat" : "sonar-runner"; final File exec = new File(path + File.separatorChar + "bin" + File.separatorChar + execName); if (!exec.exists()) { throw new RunBuildException("SonarQube executable doesn't exist: " + exec.getAbsolutePath()); } if (!exec.isFile()) { throw new RunBuildException("SonarQube executable is not a file: " + exec.getAbsolutePath()); } return exec.getAbsolutePath(); }
Example 6
Source File: FileUtils.java From OpenEphyra with GNU General Public License v2.0 | 5 votes |
/** * Recursively browses a directory and its subdirectories for files. * * @param dir a directory */ private static void getFilesRec(File dir, ArrayList<File> files) { File[] filesOrDirs = dir.listFiles(); for (File fileOrDir : filesOrDirs) if (fileOrDir.isFile()) files.add(fileOrDir); // add normal files else getFilesRec(fileOrDir, files); // browse subdirectories }
Example 7
Source File: DatabaseHelper.java From android_dbinspector with Apache License 2.0 | 5 votes |
private static void findFiles(File file, List<File> fileList) { if (file.isFile() && file.canRead()) { fileList.add(file); } else if (file.isDirectory()) { for (File fileInDir : file.listFiles()) { findFiles(fileInDir, fileList); } } }
Example 8
Source File: InFileDataSetCache.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public DataSet get(String key) { File file = resolveKey(key); if (!file.exists()) { return null; } else if (!file.isFile()) { throw new IllegalStateException("ERROR: cannot read DataSet: cache path " + file + " is not a file"); } else { DataSet ds = new DataSet(); ds.load(file); return ds; } }
Example 9
Source File: EffectiveServicesMojo.java From vespa with Apache License 2.0 | 5 votes |
@Override protected void doExecute() throws Exception { File services = new File(servicesFile); if ( ! services.isFile()) throw new IllegalArgumentException(servicesFile + " does not exist. Set correct path with -DservicesFile=<path to services.xml>"); ZoneId zone = zoneOf(environment, region); Path output = Paths.get(outputDirectory).resolve("services-" + zone.environment().value() + "-" + zone.region().value() + ".xml"); Files.write(output, effectiveServices(services, zone, InstanceName.from(instance)).getBytes(StandardCharsets.UTF_8)); getLog().info("Effective services for " + zone + " written to " + output); }
Example 10
Source File: ResourceUsageAnalyzer.java From bazel with Apache License 2.0 | 5 votes |
/** * Copies one resource directory tree into another; skipping some files, replacing the contents of * some, and passing everything else through unmodified */ private static void filteredCopy( File source, Path destination, Set<File> skip, Map<File, String> replace) throws IOException { File destinationFile = destination.toFile(); if (source.isDirectory()) { File[] children = source.listFiles(); if (children != null) { if (!destinationFile.exists()) { boolean success = destinationFile.mkdirs(); if (!success) { throw new IOException("Could not create " + destination); } } for (File child : children) { filteredCopy(child, destination.resolve(child.getName()), skip, replace); } } } else if (!skip.contains(source) && source.isFile()) { String contents = replace.get(source); if (contents != null) { Files.write(contents, destinationFile, UTF_8); } else { Files.copy(source, destinationFile); } } }
Example 11
Source File: DirectoryCleaner.java From iaf with Apache License 2.0 | 5 votes |
private void cleanupFile(File file, long lastModifiedDelta) { if (file.isDirectory()) { if (subdirectories) { log.debug("Cleanup subdirectory [" + file.getAbsolutePath() + "]"); File[] files = file.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file2 = files[i]; cleanupFile(file2, lastModifiedDelta); } } } if (deleteEmptySubdirectories) { if (file.list().length == 0) { if (file.delete()) { log.info("deleted empty subdirectory [" + file.getAbsolutePath() + "]"); } else { log.warn("could not delete empty subdirectory [" + file.getAbsolutePath() + "]"); } } } } else { if (file.isFile()) { if (FileUtils.getLastModifiedDelta(file) > lastModifiedDelta) { String fileStr = "file [" + file.getAbsolutePath() + "] with age [" + Misc.getAge(file.lastModified()) + "]"; if (file.delete()) { log.info("deleted " + fileStr); } else { log.warn("could not delete file " + fileStr); } } } } }
Example 12
Source File: InFileDataSetCache.java From nd4j with Apache License 2.0 | 5 votes |
@Override public DataSet get(String key) { File file = resolveKey(key); if (!file.exists()) { return null; } else if (!file.isFile()) { throw new IllegalStateException("ERROR: cannot read DataSet: cache path " + file + " is not a file"); } else { DataSet ds = new DataSet(); ds.load(file); return ds; } }
Example 13
Source File: FileHelper.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
/** * 读取整个目录下所有子文件的内容至String中. * * @param dir the dir * @param encoding the encoding * @return the string * @throws IOException */ public static String readEntireDirectoryContent(File dir, String encoding) throws IOException { List<File> files = searchAllNotIgnoreFile(dir); StringBuffer result = new StringBuffer(); for (File file : files) { if (file.isDirectory()) continue; if (file.isFile() && file.exists()) { result.append(IOHelper.readFile(file, encoding)); } } return result.toString(); }
Example 14
Source File: ArticleContent.java From boubei-tss with Apache License 2.0 | 5 votes |
/** * 检查发布路径是否为合法路径 */ public boolean checkPubUrl() { File pubFile = new File(pubUrl); if ( !pubFile.exists() || !pubFile.isFile() || !pubFile.getName().endsWith(".xml") ) { return false; } return true; }
Example 15
Source File: PackageMojo.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
private void attachIfNeeded(File jar) { if (jar.isFile() && classifier != null && attach) { ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact vertxJarArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "compile", "jar", classifier, handler); vertxJarArtifact.setFile(jar); this.project.addAttachedArtifact(vertxJarArtifact); } }
Example 16
Source File: AbstractGoDependencyAwareMojo.java From mvn-golang with Apache License 2.0 | 5 votes |
private void restoreGoModFromBackupAndRemoveBackup(@Nonnull final File folder) throws IOException { final Collection<File> backupFiles = FileUtils.listFiles(folder, FileFilterUtils.nameFileFilter(GO_MOD_FILE_NAME_BAK), TrueFileFilter.INSTANCE); this.getLog().debug(String.format("Restoring go.mod from backup in %s, detected %d files", folder, backupFiles.size())); for (final File backup : backupFiles) { final File restored = new File(folder, GO_MOD_FILE_NAME); if (restored.isFile() && !restored.delete()) { throw new IOException("Can't delete file during backup restore: " + restored); } if (!backup.renameTo(restored)) { throw new IOException("Can't rename backup: " + backup + " -> " + restored); } } }
Example 17
Source File: ToolSearchPath.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public CommandLineToolSearchResult locate(ToolType key, String exeName) { CommandLineToolSearchResult result = executables.get(exeName); if (result == null) { File exe = findExecutable(operatingSystem, exeName); result = exe == null || !exe.isFile() ? new MissingTool(key, exeName, pathEntries) : new FoundTool(exe); executables.put(exeName, result); } return result; }
Example 18
Source File: ParseCompileSummary.java From birt with Eclipse Public License 1.0 | 5 votes |
public static void main (String[] args){ int i=0; ParseCompileSummary report = new ParseCompileSummary(); /* Get xml result folder */ File[] xmlReports = getTestResult(args[0]); String outputPath = args[1]; countWarning = args[2]; countError = args[3]; int reportCount = xmlReports.length; /*parse arguments*/ for(i=0;i<reportCount;i++){ File ResultFileFolder = xmlReports[i]; if (ResultFileFolder.isFile()) continue; File[] files = ResultFileFolder.listFiles( new SuffixFileFilter(".xml") ); /* read junit test reports*/ PluginName = ResultFileFolder.getName(); System.out.println("Processing " + PluginName + "..." ); for (int j=0;j<files.length;++j){ ResultFile = files[j]; report.getTestResult(); report.wrtTestReport( outputPath ); } } }
Example 19
Source File: MakeJNLPTest.java From netbeans with Apache License 2.0 | 5 votes |
private static void findFilenames(File dir, String prefix, Set<String> names) { for (File f : dir.listFiles()) { if (f.isFile()) { names.add(prefix + f.getName()); } else if (f.isDirectory()) { findFilenames(f, prefix + f.getName() + "/", names); } } }
Example 20
Source File: FileUtils.java From zulip-android with Apache License 2.0 | 4 votes |
@Override public boolean accept(File file) { final String fileName = file.getName(); // Return files only (not directories) and skip hidden files return file.isFile() && !fileName.startsWith(HIDDEN_PREFIX); }