java 获取文件大小

import java.io.*;

public class Filee {
public static void main(String[] args) throws IOException {
   File f = new File("C:\\Downloads\\plato_free070821.rar");

   if (f.exists()) {

/** ///1 可以   
*
* FileInputStream fis = null;

    fis = new FileInputStream(f);

    System.out.println("File has " + fis.available()
      + " bytes");
    System.out.println("File has " + (double)((double)fis.available()/1000/1000)
      + "M");
    System.out.println("File has " + (double)(fis.available()/1024/1024)
      + "M");*/

    /** ///2 可以
    * System.out.println("文件存在");
    * System.out.println("文件大小为:"+(double)(f.length()/1024/1024)+"M");
    */
   } else {
    f.createNewFile();
    System.out.println("文件不存在");
   }
}
}

你可能感兴趣的:(java,jdk,C++,c,F#)