File f1= new File("D:\\3000.txt");
File f2= new File("D:\\2000");
System.out.println(f1.exists());
System.out.println(f2.exists());结果是false,false
D盘里面也没有任何新文件和新目录出现,请问这到底是怎么回事?
File f2= new File("D:\\2000");
System.out.println(f1.exists());
System.out.println(f2.exists());结果是false,false
D盘里面也没有任何新文件和新目录出现,请问这到底是怎么回事?
File file = new File("D:/test.txt");
file.createNewFile();
{
f1.createNewFile();
)
这句代码起到什么作用?
还有为什么不是D:\\呢?
import java.io.File;
public class Test {
public static void main(String[] args) throws Exception{
File f1= new File("D:\\3000.txt");
File f2= new File("D:\\2000");
f1.createNewFile(); //这里才是真正创建了一个文件
f2.createNewFile();
System.out.println(f1.exists());
System.out.println(f2.exists());
}
}
如果你读取,或者写入,才会真正的进行磁盘或者网络的IO操作。我们看看File的源代码
public File(String pathname) {
if (pathname == null) {
throw new NullPointerException();
}
this.path = fs.normalize(pathname);
this.prefixLength = fs.prefixLength(this.path);
}看到了,他只是做了很简单的文件名的处理而已。