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 }
相关文章:
- java IO文件操作简单基础入门例子,IO流其实没那么难 2021-12-17
- java Restful框架,jersey入门例子 2021-05-19
- Java入门9.2---NIO(Non-Blocking IO,New IO) 2021-08-29
- themeleaf入门例子 2021-06-18
- HTML入门例子 2021-12-12
- bootstrap入门例子 2021-12-06
- Vue入门例子 2022-01-07
- lucene入门例子 2021-04-26