我现在有一个File对象,代表一个目录;一个Stirng对象,代表一个文件名。
但实际上,文件系统中,在这个目录下不存在这个文件的。
我怎么才能在这个目录下用这个文件名创建一个大小为0的文件呢?
File Dir;
......
File file = new File(Dir,"filename.txt");似乎是不行的。
但实际上,文件系统中,在这个目录下不存在这个文件的。
我怎么才能在这个目录下用这个文件名创建一个大小为0的文件呢?
File Dir;
......
File file = new File(Dir,"filename.txt");似乎是不行的。
fileTarget.createNewFile();
{
if(!path.exist()){
path.makdirs();
}
FileOutputStream fis = new FileOutputStream(path.getAbs??Path() + "/" + name);
fis.close();
}
File f = new File(Dir,"test.txt");
//如果不存在,创建新文件。
//如果存在,什么都不做。
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}