1 import java.io.File;
 2 
 3 /**
 4  * File类型基本操作
 5  */
 6 
 7 /**
 8  * @author Administrator
 9  * 
10  */
11 public class FileDemo {
12 
13     /**
14      * @param args
15      */
16     public static void main(String[] args) {
17         // TODO Auto-generated method stub
18         final String PATH = "c:\\text.txt";
19         File file = new File(PATH);
20         if (file.exists()) {
21             if (file.isFile()) {
22                 System.out.println("名称:" + file.getName());
23                 System.out.println("相对路径:" + file.getPath());
24                 System.out.println("绝对路径:" + file.getAbsolutePath());
25                 System.out.println("文件大小:" + file.length() + "字节");
26             } else if (file.isDirectory()) {
27                 System.out.println("这是一个目录!");
28             }
29         } else {
30             System.out.println("文件不存在!");
31         }
32     }
33 
34 }
View Code

相关文章: