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 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/* Get File size in bytes This Java example shows how to get the size of a particular file in bytes, KB and MB using length method of Java File class. */ import java.io.*; public class GetFileSizeInByetes { public static void main(String[] args) { //create file object File file = new File("C://FileIO/demo.txt"); /* * To get the size of a file, use * long length() method of Java File class. * * This method returns size of a particular file in bytes. It returns 0L * if file does not exists, and unspecified if file is a directory. * */ long fileSize = file.length(); System.out.println("File size in bytes is: " + fileSize); System.out.println("File size in KB is : " + (double)fileSize/1024); System.out.println("File size in MB is :" + (double)fileSize/(1024*1024)); } } /* Output would be File size in bytes is: 492480 File size in KB is : 480.9375 File size in MB is :0.46966552734375 */ |
How does that work with a file on the web?