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

相关文章:

  • 2021-05-19
  • 2021-12-06
  • 2021-12-12
  • 2022-01-07
  • 2021-04-26
  • 2021-04-10
  • 2021-11-05
  • 2021-09-01
猜你喜欢
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-12-08
  • 2021-06-02
  • 2021-12-17
相关资源
相似解决方案