Created
July 2, 2012 21:01
-
-
Save timbradley/3035680 to your computer and use it in GitHub Desktop.
Find the size of a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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