List of usage examples for java.io File isFile
public boolean isFile()
From source file:IO.Files.java
/** * Returns true if the given file path exists * * @param filePath file's path/*from ww w . jav a2 s .com*/ * @return true if the given file path exists */ public static boolean IsFile(String filePath) { File f = new File(filePath); return (f.exists() && f.isFile() && !f.isDirectory()); }
From source file:Main.java
public static long getFileSize(File dirOrFile) { if (dirOrFile == null || !dirOrFile.exists()) { return 0; }/*w w w. jav a2 s . com*/ if (dirOrFile.isFile()) { return dirOrFile.length(); } if (dirOrFile.isDirectory()) { File[] subDirOrFiles = dirOrFile.listFiles(); if (subDirOrFiles == null || subDirOrFiles.length <= 0) { return 0; } long size = 0; for (File subDirOrFile : subDirOrFiles) { size += getFileSize(subDirOrFile); } return size; } return 0; }
From source file:io.cloudslang.lang.cli.SlangBootstrap.java
private static void loadUserProperties() throws IOException { String appHome = System.getProperty("app.home"); String propertyFilePath = appHome + File.separator + USER_CONFIG_FILEPATH; File propertyFile = new File(propertyFilePath); Properties rawProperties = new Properties(); if (propertyFile.isFile()) { try (InputStream propertiesStream = new FileInputStream(propertyFilePath)) { rawProperties.load(propertiesStream); }//from ww w.j a v a2 s .c o m } Set<Map.Entry<Object, Object>> propertyEntries = rawProperties.entrySet(); for (Map.Entry<Object, Object> property : propertyEntries) { String key = (String) property.getKey(); String value = (String) property.getValue(); value = substitutePropertyReferences(value); System.setProperty(key, value); } }
From source file:brut.directory.ZipUtils.java
private static void processFolder(final File folder, final ZipOutputStream zipOutputStream, final int prefixLength) throws BrutException, IOException { for (final File file : folder.listFiles()) { if (file.isFile()) { final String cleanedPath = BrutIO.sanitizeUnknownFile(folder, file.getPath().substring(prefixLength)); final ZipEntry zipEntry = new ZipEntry(BrutIO.normalizePath(cleanedPath)); // aapt binary by default takes in parameters via -0 arsc to list extensions that shouldn't be // compressed. We will replicate that behavior final String extension = FilenameUtils.getExtension(file.getAbsolutePath()); if (mDoNotCompress != null && (mDoNotCompress.contains(extension) || mDoNotCompress.contains(zipEntry.getName()))) { zipEntry.setMethod(ZipEntry.STORED); zipEntry.setSize(file.length()); BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(file)); CRC32 crc = BrutIO.calculateCrc(unknownFile); zipEntry.setCrc(crc.getValue()); unknownFile.close();/*from ww w.j a va 2 s. c o m*/ } else { zipEntry.setMethod(ZipEntry.DEFLATED); } zipOutputStream.putNextEntry(zipEntry); try (FileInputStream inputStream = new FileInputStream(file)) { IOUtils.copy(inputStream, zipOutputStream); } zipOutputStream.closeEntry(); } else if (file.isDirectory()) { processFolder(file, zipOutputStream, prefixLength); } } }
From source file:cn.dreampie.FileUtilities.java
/** * Convenience Method for turning a string path for a single file into a list of files to be processed * * @param sourceFile/* w ww . j ava 2 s . co m*/ */ public static List<File> fileToFileList(String sourceFile) { List<File> files = Lists.newArrayList(); File srcFile = new File(sourceFile); if (srcFile.exists() && srcFile.isFile()) { files.add(srcFile); } return files; }
From source file:Main.java
public static List<String> getSubtitlePath(String videoPath) { List<String> sbPathList = new ArrayList<String>(); if (TextUtils.isEmpty(videoPath)) return sbPathList; if (videoPath.contains("file")) { videoPath = videoPath.substring(7); }/* w w w . ja v a 2s . c o m*/ int end = videoPath.lastIndexOf("/", videoPath.length()); String path = videoPath.substring(0, end + 1); end = videoPath.lastIndexOf(".", videoPath.length()); if (-1 == end || null == path) return sbPathList; String subffix = videoPath.substring(0, end); File files = new File(path); if ((files != null) && (files.exists()) && (files.isDirectory())) { File[] filesInDir = files.listFiles(); long count = filesInDir.length; for (int num = 0; num < count; num++) { String filePath = filesInDir[num].getPath(); File subTitleFile = new File(filePath); if ((subTitleFile != null) && (subTitleFile.isFile()) && (subTitleFile.canRead())) { int pos = filePath.lastIndexOf(".", filePath.length()); String sub = filePath.substring(pos + 1, filePath.length()); if ((filePath.startsWith(subffix)) && (sub != null) && ((sub.equalsIgnoreCase("srt")) || (sub.equalsIgnoreCase("ass")) || (sub.equalsIgnoreCase("smi")) || (sub.equalsIgnoreCase("ssa")))) { sbPathList.add(filePath); } } } if (sbPathList.size() != 0) { return sbPathList; } } return sbPathList; }
From source file:io.apiman.gateway.platforms.war.micro.Users.java
/** * @throws Exception /*from ww w. ja v a2s . co m*/ */ private static URL getUsersUrl() throws Exception { String usersLoc = System.getProperty(USERS_FILE_PROP); if (usersLoc == null) { return null; } // Try a file first. try { File usersFile = new File(usersLoc); if (usersFile.isFile()) { return usersFile.toURI().toURL(); } } catch (Exception e) { } // Try it as a URL. URL url = new URL(usersLoc); return url; }
From source file:Main.java
public static boolean checkFilesIsNeedDelete(String path, long intervalTime) { File file = new File(path); if (file == null && !file.exists()) { return false; }// w w w . j a v a 2 s . co m if (file.isFile()) { deleteFileByIntervalTime(file, intervalTime); } else { File[] fileList = file.listFiles(); for (int i = 0; i < fileList.length; i++) { File temp = fileList[i]; if (temp.isDirectory()) { checkFilesIsNeedDelete(temp.getAbsolutePath(), intervalTime); } else { deleteFileByIntervalTime(temp, intervalTime); } } } return true; }
From source file:Main.java
public static boolean deleteFiles(String path) { File file = new File(path); boolean flag = false; if (file == null) { return flag; }//from www . ja v a 2 s .co m if (file.isFile()) { file.delete(); } else if (file.isDirectory()) { File[] fileList = file.listFiles(); for (int i = 0; i < fileList.length; i++) { flag = deleteFiles(fileList[i].getAbsolutePath()); // if(!flag){ // break; // } } } return flag; }
From source file:com.timeinc.seleniumite.environment.RawTestScript.java
public static RawTestScript fromFile(File f) { if (f.exists() && f.isFile()) { try {//from w ww .j a v a2 s .co m return new RawTestScript().withName(f.getName()) .withRawTestContents(IOUtils.toString(new FileInputStream(f))).withOptionalSourceFile(f); } catch (IOException ioe) { throw new RuntimeException("Shouldnt happen", ioe); } } else { throw new IllegalArgumentException("Cant process - doesnt exist or isnt a file : " + f); } }