我现在假如D盘有个文本文件,现在我怎么判断这个文件的大小 大于 1M?用JAVA实现,谢谢!

解决方案 »

  1.   

    file.length()得到的是byte,然后你转成M就可以了!
      

  2.   

    File.length();
    FileInputStream stream = new FileInputStream("file");
    int len = stream.avaiable();一般也可以用这个方法得到一个文件的长度。
      

  3.   

    new File("d:/demo.txt").length()/1024/1204 > 1
      

  4.   

    import java.io.*;
    public class TT1{
    public static void main(String[] args) throws IOException{
    try{
        FileInputStream stream = new     FileInputStream("ms13-4-2004.wrf");
        int len = stream.available(); 
    if(len/1024/1024>1){
    System.out.println(len);}
    }catch(IOException e){System.out.println(e);}
    }
    }
    文件ms13-4-2004.wrf要与程序在一个目录下
      

  5.   

    或者FileInputStream stream = new     FileInputStream("d:/a.txt");
      

  6.   

    这个帖子也要50分,楼主我接点分哈,上面的同志都说完了,正确的哈.就是这种哈:
    new File("d:/demo.txt").length()/1024/1204 > 1