How to get file size in Java?

The File.length() method get the file size in bytes.

Example: D:\\tmp\\nourit.txt  201Bytes

package com.nourit.javaIO;


public class GetFileSizeExample {

  public static void main(String[] args) {
    File file = new File("D:\\tmp\\nourit.txt");
      double bytes = file.length();
      System.out.println(bytes + " Bytes");



201.0 Bytes



IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.