package com.xuexi.IO; import java.io.File; import java.io.IOException; public class FileTest { public static void main(String[] args) { File file = new File("E:","2016.txt"); System.out.println("文件存在吗?"+file.exists()); System.out.println("文件隐藏看吗?"+file.isHidden()); System.out.println("文件可读吗?"+file.canRead()); System.out.println("文件可写吗?"+file.canWrite()); System.out.println("文件名?"+file.getName()); System.out.println("文件长度?"+file.length()); System.out.println("文件绝对路径?"+file.getAbsolutePath()); System.out.println("文件相对路径?"+file.getPath()); System.out.println("是目录吗?"+file.isDirectory()); //file.deleteOnExit(); 删除文件 File file2 = new File("."); File[] name = file2.listFiles(); for(int i = 0;i<name.length;i++){ System.out.println(name[i]); } File file3 = new File("E:\JAVA\com.xuexi.mianxiang\src\com\xuexi\IO"); String[] name1 = file3.list(); System.out.println("开始遍历"); for(String string:name1){ System.out.println(string); } //若当前路径下有此文件则返回FALSE,否则创建一个空文件返回TRUE /*try { boolean m=file.createNewFile(); System.out.println(m); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ /* boolean n = file.mkdir();//创建一个文件夹 System.out.println(n);*/ boolean k = file.mkdirs(); System.out.println(k); //执行可执行文件 /*Runtime runtime = Runtime.getRuntime(); File file4 = new File("D:\VC98\Bin","MSDEV"); try{ runtime.exec(file4.getAbsolutePath()); }catch( IOException e){ e.printStackTrace(); }*/ } }