集册 Java实例教程 获取文件大小(字节)

获取文件大小(字节)

欢马劈雪     最近更新时间:2020-01-02 10:19:05

553
获取文件大小(以字节为单位)


import java.io.*;

 

public class Main {/* from 时 代 J a v a 公 众 号*/

 

  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));

  }

}