我的程序是这样的,我的问题是为什么我的file创建不成功,总是“does not exist”,要怎样才能创建成功?
- Java code
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"); }}
------解决方案--------------------
import java.io.*;
- Java code
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"); }}
------解决方案--------------------
- Java code
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"); }}