1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package org.arpit.java2blog; import java.io.File; public class GetSizeOfFileMain { public static void main(String[] args) { // Read the file File mp3File=new File("/Users/Arpit/Desktop/MySong.mp3"); // Use length method to get size of file in bytes double fileSizeinBytes=mp3File.length(); System.out.println( "Size of file in bytes :" +fileSizeinBytes + " bytes"); System.out.println( "Size of file in KB :" +(double)fileSizeinBytes/1024 + " KB"); System.out.println( "Size of file in MB :" +(double)fileSizeinBytes/(1024*1024) + " MB"); } } |
1 2 3 4 5 |
Size of file in bytes :3699969.0 bytes Size of file in KB :3613.2509765625 KB Size of file in MB :3.5285654067993164 MB |