1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| package code;
import java.io.File; import java.io.IOException;
public class IOStream { public static void main(String[] args) { File f = new File("F:\\test.txt"); System.out.println("文件路径为:" + f.getAbsolutePath()); System.out.println("文件的大小为:" + f.length()); System.out.println("文件可读不:" + f.canRead()); File f1=new File("F:\\test1.txt"); if(!f1.exists()) { try { f1.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else System.out.println("文件已存在!不需要创建!"); File f2 = new File("F:\\javaFileoper\\test"); if(f2.isDirectory()) { System.out.println("文件夹已存在!"); } else { f2.mkdir(); } File f3=new File("F:\\"); if(f3.isDirectory()) { File lists[]=f3.listFiles(); for(int i=0;i<lists.length;i++) { System.out.println("文件名:"+lists[i].getName()); } } } }
|