日期:2014-05-20 浏览次数:20828 次
package files; import java.io.*; class FileDemo { static void p(String s) { System.out.println(s); } public static void main(String args[]) { File f1=new File("f://test.txt"); p("File Name:"+f1.getName()); p("Path:"+f1.getPath()); p("Abs Path:"+f1.getAbsolutePath()); p("Parent:"+f1.getParent()); p(f1.exists()?"exists":"does not exist"); } }
class FileDemo { static void p(String s) { System.out.println(s); } public static void main(String args[]) [color=#FF00FF]throws IOException[/color] { File f1=new File("f://test.txt"); [color=#FF00FF]f1.createNewFile();[/color] p("File Name:"+f1.getName()); p("Path:"+f1.getPath()); p("Abs Path:"+f1.getAbsolutePath()); p("Parent:"+f1.getParent()); p(f1.exists()?"exists":"does not exist"); } }
------解决方案--------------------
package files; import java.io.*; class FileDemo { static void p(String s) { System.out.println(s); } public static void main(String args[]) { File f1=new File("f://test.txt"); [color=#FF0000]f1.createNewFile();[/color] p("File Name:"+f1.getName()); p("Path:"+f1.getPath()); p("Abs Path:"+f1.getAbsolutePath()); p("Parent:"+f1.getParent()); p(f1.exists()?"exists":"does not exist"); } }