| java 取得文件大小 |
|
|
|
| J2EE综合 |
| 作者是 Administrator |
| 2007-11-29 15:13 |
|
package c.file; 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("文件不存在"); } } } |
| 最近更新 ( 2007-11-29 15:13 ) |



