createfiledemo3.java
来自「JAVA编程思想源代码 值得一下 很难找的」· Java 代码 · 共 35 行
JAVA
35 行
package chapter10;
import java.io.File;
import java.io.IOException;
public class CreateFileDemo3 {
public static void main(String[] args) {
File f1 = new File("C:\\test");
File f2 = new File("C:\\test", "test1.txt");
File f3 = new File(f1, "test2.txt");
if (!f1.exists()) {
f1.mkdir();
}
try {
if (!f2.exists()) {
System.out.println("C:\\test目录下的test1.txt文件不存在,创建中。。。");
f2.createNewFile();
System.out.println("创建成功!");
}
if (!f3.exists()) {
System.out.println("C:\\test目录下的test2.txt文件不存在,创建中。。。");
f3.createNewFile();
System.out.println("创建成功!");
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("f2的路径为:" + f2.getPath());
System.out.println("f3的路径为:" + f3.getPath());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?