- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- /**
- * @author
- *
- */
- public class FileTest {
- public static void main(String[] args) throws IOException {
- File f = new File("D:\\JDK_API_1_6_zh_CN.CHM");
- if (f.exists()) {
- 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");
- System.out.println("文件大小为:"+(double)(f.length()/1024/1024)+"M");
- } else {
- f.createNewFile();
- System.out.println("文件不存在");
- }
- }
- }