long getSize(final String filename, final long defaultSize) { if (filename == null) return defaultSize; File file = new File(filename); if (!file.exists()) return defaultSize; return file.length(); }
void exampleUse() { long size = getSize("/etc/passwd", -1); if (size < 0) { // doesn't exist or I can't access it } }