List of usage examples for java.io File isFile
public boolean isFile()
From source file:Main.java
public static boolean deleteFiles(String folder) { if (folder == null || folder.length() == 0 || folder.trim().length() == 0) { return true; }//from w w w. j a va 2 s . c om File file = new File(folder); if (!file.exists()) { return true; } if (file.isFile()) { return file.delete(); } if (!file.isDirectory()) { return false; } for (File f : file.listFiles()) { if (f.isFile()) { f.delete(); } else if (f.isDirectory()) { deleteFile(f.getAbsolutePath()); } } return file.delete(); }
From source file:Main.java
public static boolean deleteFileRecursively(String path) { File destFile = new File(path); if (!destFile.exists()) { return true; }/*from w w w . ja v a 2s. c o m*/ if (destFile.isFile()) { destFile.delete(); return true; } String[] childNames = destFile.list(); for (String child : childNames) { if (!deleteFileRecursively(new File(path, child).getAbsolutePath())) { return false; } } return destFile.delete(); }
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); }/* www. j a v a2 s .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")) || (sub.equalsIgnoreCase("sub")))) { sbPathList.add(filePath); } } } if (sbPathList.size() != 0) { return sbPathList; } } return sbPathList; }
From source file:com.cloudera.knittingboar.utils.DataUtils.java
public static synchronized File getTwentyNewsGroupDir() throws IOException { if (twentyNewsGroups != null) { return twentyNewsGroups; }/*from w ww.j av a 2s.c om*/ // mac gives unique tmp each run and we want to store this persist // this data across restarts File tmpDir = new File("/tmp"); if (!tmpDir.isDirectory()) { tmpDir = new File(System.getProperty("java.io.tmpdir")); } File baseDir = new File(tmpDir, TWENTY_NEWS_GROUP_LOCAL_DIR); if (!(baseDir.isDirectory() || baseDir.mkdir())) { throw new IOException("Could not mkdir " + baseDir); } File tarFile = new File(baseDir, TWENTY_NEWS_GROUP_TAR_FILE_NAME); if (!tarFile.isFile()) { FileUtils.copyURLToFile(new URL(TWENTY_NEWS_GROUP_TAR_URL), tarFile); } Process p = Runtime.getRuntime() .exec(String.format("tar -C %s -xvf %s", baseDir.getAbsolutePath(), tarFile.getAbsolutePath())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); System.out.println("Here is the standard error of the command (if any):\n"); String s; while ((s = stdError.readLine()) != null) { System.out.println(s); } stdError.close(); twentyNewsGroups = baseDir; return twentyNewsGroups; }
From source file:dev.meng.wikipedia.profiler.Cleaner.java
public static void cleanData(List<String> values) { for (String value : values) { try {/*from w w w .j a v a 2 s. c o m*/ Path filepath = Paths.get(value); File file = filepath.toFile(); if (file.exists()) { if (file.isFile()) { Files.delete(filepath); } else if (file.isDirectory()) { FileUtils.deleteDirectory(file); } } } catch (IOException ex) { LogHandler.console(Cleaner.class, ex); } } }
From source file:Main.java
public static File createFolders() { File baseDir;/*from w w w . ja va2s . c o m*/ if (android.os.Build.VERSION.SDK_INT < 8) { baseDir = Environment.getExternalStorageDirectory(); } else { baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); } if (baseDir == null) return Environment.getExternalStorageDirectory(); File aviaryFolder = new File(baseDir, FOLDER_NAME); if (aviaryFolder.exists()) return aviaryFolder; if (aviaryFolder.isFile()) aviaryFolder.delete(); if (aviaryFolder.mkdirs()) return aviaryFolder; return Environment.getExternalStorageDirectory(); }
From source file:fr.paris.lutece.plugins.swaggerui.service.SwaggerFileService.java
/** * Find directories that contains swagger files * @param listSwaggerDirectories The directory list * @param parentDirectory The parent directory *//*ww w .ja v a 2s.co m*/ private static void findDirectory(List<File> listSwaggerDirectories, File parentDirectory) { File[] listFiles = parentDirectory.listFiles(); if (listFiles != null) { for (File file : listFiles) { if (file.isFile()) { continue; } if (file.getName().equals(SWAGGER_DIRECTORY_NAME)) { listSwaggerDirectories.add(file); } if (file.isDirectory()) { findDirectory(listSwaggerDirectories, file); } } } }
From source file:Main.java
public static boolean deleteFile(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); if (!fileName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + fileName); checker.checkDelete(newPath.toString()); if (newPath.isFile()) { try { Log.i("DirectoryManager deleteFile", fileName); newPath.delete();/*from w w w . j a va2 s .c o m*/ status = true; } catch (SecurityException se) { se.printStackTrace(); status = false; } } else status = false; } else status = false; return status; }
From source file:com.github.jrh3k5.mojo.flume.io.ArchiveUtils.java
/** * Un-GZIP a file./*from w ww . j av a 2 s. c o m*/ * * @param toUnzip * A {@link URL} representing the GZIP file to be unzipped. * @param toFile * A {@link File} representing the location to which the unzipped file should be placed. * @throws IOException * If any errors occur during the unzipping. * @see #gzipFile(File, File) */ public static void gunzipFile(URL toUnzip, File toFile) throws IOException { if (toFile.exists() && !toFile.isFile()) { throw new IllegalArgumentException("Destination file " + toFile + " exists, but is not a file and, as such, cannot be written to."); } GZIPInputStream zipIn = null; FileOutputStream fileOut = null; try { zipIn = new GZIPInputStream(toUnzip.openStream()); fileOut = new FileOutputStream(toFile); IOUtils.copy(zipIn, fileOut); } finally { IOUtils.closeQuietly(fileOut); IOUtils.closeQuietly(zipIn); } }
From source file:luceneprueba.utils.FileParser.java
static public void createFilesFromJSONArray() throws IOException { File dir = new File("files/input"); File[] files = dir.listFiles(); if (files == null) { System.out.println("No existe la carpeta \'input\' dentro de la carpeta files."); return;/*from www. j ava 2 s .c o m*/ } if (files.length == 0) { System.out.println("No hay ningun archivo en la carpeta \'input\' para ser indexado"); return; } BufferedReader br; String fileContent; JSONArray jsonArray = null; JSONParser jsonParser = new JSONParser(); int i = 1; FileWriter datosReviews = null; try { datosReviews = new FileWriter("files/output/datos_reviews.txt"); } catch (IOException ex) { ex.printStackTrace(System.out); } for (File file : files) { if (file.isFile() && file.canRead() && file.getName().endsWith(".txt")) { System.out.println("Leyendo el archivo: " + file.getName()); FileWriter contentReviews; try { br = new BufferedReader(new FileReader(file)); fileContent = br.readLine(); jsonArray = (JSONArray) jsonParser.parse(fileContent); Iterator it = jsonArray.iterator(); DecimalFormat formato = new DecimalFormat("000000"); while (it.hasNext()) { JSONObject json = (JSONObject) it.next(); if (json.get("Genre") != null && json.get("Date") != null) { contentReviews = new FileWriter( "files/output/clasificador/review_clasificador_" + formato.format(i) + ".txt"); datosReviews.write(Integer.toString(i) + "_" + (String) json.get("Date") + "_" + (String) json.get("Genre") + "_" + (String) json.get("Score") + "\n"); contentReviews.write(Integer.toString(i) + " " + (String) json.get("Review")); i++; contentReviews.close(); } } br.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(System.out); } catch (IOException | ParseException ex) { ex.printStackTrace(System.out); } } } datosReviews.close(); }