Get File size in bytes - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Get File size in bytes

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
    File file = new File("C://Folder/demo.txt");
     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));
  }/*from   w ww  .j av  a 2s  .  co  m*/
}

Result


Related Tutorials