文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>java 获取文件大小

java 获取文件大小

时间:2010-07-16  来源:云少嘎嘎嘎

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("文件不存在");
   }
}
}

转自http://lanxulin.javaeye.com/blog/627256

相关阅读 更多 +
排行榜 更多 +
别惹神枪手安卓版

别惹神枪手安卓版

冒险解谜 下载
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载