Java 1 2 3 int getTextFileSize (String fileName) { return ( int ) ( new File(BASE_DIR, fileName).length(); // WRONG } And if your code is not going to deal with files larger than 2GB, why worry? Adding integers in most languages results in int and automatic overflows into a negative number (and even worse, back to a positive number).