麻烦帮忙检查
来源:2-7 自由编程
慕沐1462760
2020-08-27 16:08:49
public static void main(String[] args) {
File file = new File("c:\\File\\Monday.docx");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (file.exists()) {
System.out.println("创建文件成功!");
System.out.println("文件名称:" + file.getName());
System.out.println("文件上一级目录:" + file.getParent());
boolean a = file.isDirectory();
if (a) {
System.out.println("文件/目录:这是一个目录");
} else {
System.out.println("文件/目录:这是一个文件");
}
}
}
1回答
同学你好,测试同学代码是可以,但还有一个问题:
根据作业要求还需要判断文件是否可读、可写,建议同学将该功能补全完整
祝学习愉快~
相似问题