Java tutorial
//package com.java2s; import java.io.File; public class Main { public static long getFileSize(String fn) { File f = null; long size = 0; try { f = new File(fn); size = f.length(); } catch (Exception e) { e.printStackTrace(); } finally { f = null; } return size < 0 ? null : size; } public static long getFileSize(File fn) { return fn == null ? 0 : fn.length(); } }