Here you can find the source of getFileSize(String filePath)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static double getFileSize(String filePath)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Main { /**/* w ww . j a v a 2s . c o m*/ * java get the file size * * @param file * @return * @throws Exception */ public static double getFileSize(File file) { double size = 0; try { if (file.exists()) { FileInputStream fis = null; fis = new FileInputStream(file); size = fis.available(); fis.close(); } else { return 0; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return size; } /** * java get the file size * * @param file * @return * @throws Exception */ public static double getFileSize(String filePath) { File file = new File(filePath); return getFileSize(file); } }