我的程序是这样的,我的问题是为什么我的file创建不成功,总是“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"); 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.*;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");
}
}
楼主【another1019】截止到2008-07-28 13:46:56的历史汇总数据(不包括此帖):
发帖的总数量:2 发帖的总分数:20 每贴平均分数:10
回帖的总数量:2 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:2 结贴的总分数:20
无满意结贴数:1 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:50.00 % 无满意结分率:0.00 %
敬礼!
没有创建文件
需要create()
class FileDemo
{
static void p(String s)
{
System.out.println(s);
}
public static void main(String args[]) throws IOException
{
File f1=new File("f://test.txt");
f1.createNewFile(); 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");
f1.createNewFile();
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");
}
}
都API里查看下具体的用法