Skip to content

Instantly share code, notes, and snippets.

@timbradley
Created July 2, 2012 21:01
Show Gist options
  • Select an option

  • Save timbradley/3035680 to your computer and use it in GitHub Desktop.

Select an option

Save timbradley/3035680 to your computer and use it in GitHub Desktop.
Find the size of a file
import java.io.File;
public class FileUtil {
public long getFileSize(String filename) {
File file = new File(filename);
if (!file.exists() || !file.isFile()) {
System.out.println("File doesn\'t exist");
return -1;
}
//Here we get the actual size
return file.length();
}
public static void main(String[] args) {
FileUtil fileutil = new FileUtil();
long size = fileutil.getFileSize("/Users/Tim Bradley/Desktop/swt-foundation-syllabus.pdf");
System.out.println("Filesize in bytes: " + size);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment