List of usage examples for java.io File isFile
public boolean isFile()
From source file:eu.delving.x3ml.X3MLCommandLine.java
static File file(String name) { File file = new File(name); if (!file.exists() || !file.isFile()) { error("File does not exist: " + name); }//from w w w .j a v a2s . c o m return file; }
From source file:Main.java
public static String readFile(String filePath) { File file = new File(filePath); StringBuilder fileContent = new StringBuilder(""); if (file == null || !file.isFile()) { return fileContent.toString(); }/*from ww w .jav a 2 s .c om*/ BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String line = null; while ((line = reader.readLine()) != null) { if (!fileContent.toString().equals("")) { fileContent.append("\r\n"); } fileContent.append(line); } reader.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (Exception e1) { e1.printStackTrace(); } } } return fileContent.toString(); }
From source file:ca.weblite.xmlvm.ConstantPoolHelper.java
/** * Removes dependencies on the constant pool file for all .m, .c, and .h files in the * given directory. It will use the constant_pool.m file for that directory. * @param srcDir// ww w . ja v a 2s .c om * @throws IOException */ public static void removeConstantPoolDependencies(File srcDir) throws IOException { File poolFile = new File(srcDir, "constant_pool.m"); Map<Integer, Constant> constantPool = loadConstantPool(poolFile); for (File f : srcDir.listFiles()) { if (f.isFile() && (f.getName().endsWith(".m") || f.getName().endsWith(".c") || f.getName().endsWith(".h"))) { removeConstantPoolDependencies(constantPool, f); } } }
From source file:ch.ethz.topobench.ProduceLP.java
/** * Deletion of possibly multiple folder and * files within those folders (not recursively). * * Skips .gitignore and README files.// ww w. j av a 2 s.c o m * * Adapted from: * http://stackoverflow.com/questions/7768071/how-to-delete-directory-content-in-java * * @param folders Folder to delete */ private static void removeFilesIn(String... folders) { for (String fol : folders) { File folder = new File(fol); File[] files = folder.listFiles(); if (files != null) { for (File f : files) { if (f.isFile() && !f.getName().equals(".gitignore") && !f.getName().equals("README")) { f.delete(); } } } } }
From source file:Main.java
public static void rm(File f) { if (f.isDirectory()) { for (File ff : f.listFiles()) { rm(ff);/* w w w .j a v a2 s . co m*/ } f.delete(); } else if (f.isFile()) { f.delete(); } }
From source file:Main.java
public static void copyFile(File fromFile, File toFile, Boolean rewrite) { if (!fromFile.exists()) { return;/*from ww w . jav a2s. c o m*/ } if (!fromFile.isFile()) { return; } if (!fromFile.canRead()) { return; } if (!toFile.getParentFile().exists()) { toFile.getParentFile().mkdirs(); } if (toFile.exists() && rewrite) { toFile.delete(); } try { java.io.FileInputStream fosfrom = new java.io.FileInputStream(fromFile); java.io.FileOutputStream fosto = new FileOutputStream(toFile); byte bt[] = new byte[1024]; int c; while ((c = fosfrom.read(bt)) > 0) { fosto.write(bt, 0, c); } fosfrom.close(); fosto.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
@SuppressWarnings("deprecation") public static int[] getBitmapSize(File file, int targetWidth, int targetHeight) { if (null != file && file.exists() && file.isFile() && file.canRead()) { String path = file.getAbsolutePath(); Options opts = new Options(); if (targetWidth > 0 && targetHeight > 0) { opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, opts); opts.inSampleSize = computeSampleSize(opts, Math.min(targetWidth, targetHeight), targetWidth * targetHeight); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { opts.inInputShareable = true; opts.inPurgeable = true; }/*from w w w .j a v a 2 s .co m*/ } BitmapFactory.decodeFile(path, opts); return new int[] { opts.outWidth, opts.outHeight }; } return null; }
From source file:Main.java
public static List<String> readFileToList(String filePath, String charsetName) { File file = new File(filePath); List<String> fileContent = new ArrayList<String>(); if (!file.isFile()) { return null; }/*from w w w .j a va 2s. co m*/ BufferedReader reader = null; try { InputStreamReader is = new InputStreamReader(new FileInputStream(file), charsetName); reader = new BufferedReader(is); String line = null; while ((line = reader.readLine()) != null) { fileContent.add(line); } reader.close(); return fileContent; } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }
From source file:com.hazelcast.qasonar.utils.WhiteListBuilder.java
public static WhiteList fromJsonFile() { File file = new File(WHITE_LIST_FILENAME); if (!file.exists() || !file.isFile()) { return new WhiteList(); }/*from ww w . j a v a 2 s.c o m*/ return fromJsonFile(WHITE_LIST_FILENAME); }
From source file:ImageUtil.java
/** * get image thumbnail// w w w. j av a 2 s. c o m * @param imageFile */ public static ImageIcon getImageThumbnail(File imageFile, int width, int height) { ImageIcon thumbnail = null; if (imageFile != null && imageFile.isFile()) { ImageIcon tmpIcon = new ImageIcon(imageFile.getPath()); if (tmpIcon != null) { if (tmpIcon.getIconWidth() > width) { int targetHeight = width / tmpIcon.getIconWidth() * tmpIcon.getIconHeight(); if (targetHeight > height) { targetHeight = height; } else { targetHeight = -1; } thumbnail = new ImageIcon( tmpIcon.getImage().getScaledInstance(width, targetHeight, Image.SCALE_AREA_AVERAGING)); } else { thumbnail = tmpIcon; } } } return thumbnail; }