List of usage examples for java.io File length
public long length()
From source file:Main.java
public static String calcSha1(File file) { long fileLength = file.length(); if (fileLength <= 4 * 1024 * 1024) { return smallFileSha1(file); } else {/* w w w .j a v a 2 s .c o m*/ return largeFileSha1(file); } }
From source file:Main.java
private static long getDirSize(File file) { long total = 0; if (file.exists()) { if (file.isFile()) { return file.length(); } else if (file.isDirectory()) { for (File f : file.listFiles()) { total += getDirSize(f);//from ww w .j a v a 2s . co m } } } return total; }
From source file:Main.java
public static long getFileSize(File file) { long size = 0; if (file.exists()) { if (file.isFile()) { size = file.length(); } else if (file.isDirectory()) { for (File tmp : file.listFiles()) { size += getFileSize(tmp); }/* ww w . j a va2s . com*/ } } return size; }
From source file:Main.java
public static String getFileContent(File file) { FileInputStream f = null;//w ww .ja v a 2 s.c o m try { byte[] buffer = new byte[(int) file.length()]; f = new FileInputStream(file); f.read(buffer); return new String(buffer); } catch (IOException e) { throw new RuntimeException(e); } finally { closeAll(f); } }
From source file:Main.java
public static String encodeBase64File(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer);//from ww w .ja v a2 s . co m inputFile.close(); return android.util.Base64.encodeToString(buffer, Base64.DEFAULT); }
From source file:Main.java
public static String FiletoBase64(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer);//w ww. j av a 2 s .c om inputFile.close(); return new String(Base64.encodeBase64(buffer)); }
From source file:Main.java
public static String encodeBase64File(String path) throws Exception { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer);//from w w w . j a va2 s .c om inputFile.close(); return Base64.encodeToString(buffer, Base64.DEFAULT); }
From source file:com.qwazr.search.index.BackupStatus.java
final static BackupStatus newBackupStatus(File backupDir) { if (backupDir == null) return null; try {/*from ww w . j a v a 2 s. c o m*/ long generation = Long.parseLong(backupDir.getName()); File[] files = backupDir.listFiles((FileFilter) FileFileFilter.FILE); long bytes_size = 0; if (files == null) return null; for (File file : files) bytes_size += file.length(); return new BackupStatus(generation, backupDir.lastModified(), bytes_size, files.length); } catch (NumberFormatException e) { return null; } }
From source file:Main.java
public static long folderSize(File directory) { long length = 0; try {/* ww w .j a va 2 s . c om*/ for (File file : directory.listFiles()) { if (file.isFile()) length += file.length(); else length += folderSize(file); } } catch (Exception e) { e.printStackTrace(); } return length; }
From source file:Main.java
/** * Get folder size recursively/*ww w.j av a 2s . c o m*/ * @param directory File * @return long */ public static long getFolderSizeRecursively(File directory) { long length = 0; for (File file : directory.listFiles()) { if (file.isFile()) { length += file.length(); } else { length += getFolderSizeRecursively(file); } } return length; }