首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

file有关问题

2011-12-19 
file问题我的程序是这样的,我的问题是为什么我的file创建不成功,总是“does not exist”,要怎样才能创建成功

file问题
我的程序是这样的,我的问题是为什么我的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");    }} 

热点排行
Bad Request.