package IOliu; import java.io.File; import java.io.IOException; public class FileTest { public static void main(String[] args) { File file = new File("D:","0815.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(); 程序运行结束后删除 System.out.println("文件存在吗?"+file.exists());*/ /*file.delete(); 程序立刻删除 System.out.println("文件存在吗?"+file.exists());*/ //若当前文件有对应文件,返回false,没有对应文件,则返回true,且创建对应的新文件 boolean b = false; try { b = file.createNewFile(); System.out.println("文件创建成功"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println(b); //遍历文件路径 File file2 = new File("."); File [] FileNames = file2.listFiles(); for(int i = 0 ; i < FileNames.length; i++){ System.out.println(FileNames[i]); } //遍历文件里清单 File file3 = new File("D:\JDK\eclipse\I0\src\IOliu"); String[] names2 = file3.list(); System.out.println("开始遍历!"); for(String string : names2){ System.out.println(string); } //执行项目中可执行文件 Runtime runtime = Runtime.getRuntime(); File file4 = new File("E:\小霸王游戏机-珍藏84合1 模拟器+84款经典游戏","smynesc.exe"); try{ runtime.exec(file4.getAbsolutePath()); }catch(IOException e){ e.printStackTrace(); } } }