List of usage examples for java.io File length
public long length()
From source file:Main.java
private static void writeBitmap(Bitmap bitmap, String path) throws IOException { OutputStream out = null;//from w w w. j a v a2 s. com try { File file = new File(path); if (file.exists() && file.length() > 0) return; out = new BufferedOutputStream(new FileOutputStream(file), 4096); if (bitmap != null) bitmap.compress(CompressFormat.JPEG, 90, out); } catch (Exception e) { Log.e(TAG, "writeBitmap failed : " + e.getMessage()); } finally { if (out != null) { out.close(); } } }
From source file:Main.java
public static boolean installNormal(Context context, String filePath) { Intent intent = new Intent(Intent.ACTION_VIEW); File file = new File(filePath); if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) { return false; } else {/*from w w w . ja v a 2 s . co m*/ intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; } }
From source file:Main.java
public static String getSHA(File f) { return getSHA(f, (int) f.length()); }
From source file:Main.java
public static long getFileSize(String filePath) { long size = 0; File file = new File(filePath); if (file != null && file.exists()) { size = file.length(); }/*from ww w. j a v a2s .c o m*/ return size; }
From source file:Main.java
public static long getFileSize(String filePath) { long size = 0; File file = new File(filePath); if (file != null && file.exists()) { size = file.length(); }//from www . j a va 2s.c om return size; }
From source file:Main.java
public static long getDirectorySize(File path) { if (!path.isDirectory()) { return path.length(); }//from w w w .j a va 2 s.c o m long size = 0; if (path.exists()) { File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { size += getDirectorySize(files[i]); } else { size += files[i].length(); } } } return size; }
From source file:Main.java
public static String readFile(String pathname) { File file = new File(pathname); StringBuilder fileContents = new StringBuilder((int) file.length()); String lineSeparator = System.getProperty("line.separator"); try {/*from w ww .java 2 s . c om*/ try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { fileContents.append(scanner.nextLine()).append(lineSeparator); } return fileContents.toString(); } } catch (FileNotFoundException e) { e.printStackTrace(); } return ""; }
From source file:Util.java
public static long getFileSizeInBytes(String fileName) { long ret = 0; File f = new File(fileName); if (f.isFile()) { return f.length(); } else if (f.isDirectory()) { File[] contents = f.listFiles(); for (int i = 0; i < contents.length; i++) { if (contents[i].isFile()) { ret += contents[i].length(); } else if (contents[i].isDirectory()) ret += getFileSizeInBytes(contents[i].getPath()); }// www . j a v a 2s.co m } return ret; }
From source file:Main.java
public static String getStringFromFile(String file) throws IOException { char[] data = null; FileReader fr = null;//from w ww. jav a 2s. co m try { File f = new File(file); data = new char[(int) f.length()]; fr = new FileReader(f); fr.read(data); } catch (IOException e) { throw e; } finally { if (fr != null) { try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } } return new String(data); }
From source file:com.addthis.hydra.data.MakeBloom.java
public static String[] getWords(File in) throws java.io.IOException, com.addthis.maljson.JSONException { log.debug("Reading " + in.length() + " bytes from [" + in + "]"); JSONArray words = new JSONArray("[" + new String(LessFiles.read(in), "utf8") + "]"); log.debug("Read " + words.length() + " words from [" + in + "]"); String[] ret = new String[words.length()]; for (int i = 0; i < words.length(); i++) { ret[i] = words.getString(i);//from ww w . ja v a2s .co m } return ret; }