请老师帮我看下程序有哪些错误
来源:2-7 自由编程
qq_就是这样_1
2019-06-13 23:26:12
package com.filetest.www;
import java.io.File;
import java.io.IOException;
public class MondayFile {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file1=new File("D:\\编译\\File");
if(!file1.exists()){
file1.mkdir();
}
File file2=new File(file1,"Monday.docx");
if(!file2.exists()){
try {
file2.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println("创建文件成功!");
}
System.out.println("创建文件成功!");
System.out.println("文件名称:"+file2.getName());
System.out.println("文件上一级目录:"+file1.getName());
System.out.print("文件/目录:");
if(file2.isFile()){
System.out.println("这是一个文件");
}else{
System.out.println("这是一个目录");
}
System.out.print("读写性:");
if(file2.canRead()){
System.out.print("这个文件只可以读");
}else if(file2.canWrite()){
System.out.print("这个文件只可以写");
}else{
System.out.print("这个文件既可以读还可以写");
}
}
}1回答
吃吃吃鱼的猫
2019-06-14
同学你好,程序没有错误,但是运行过程中有一个需要注意的地方:D盘下需要有名为“编译”的目录哦~
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
相似问题
回答 1
回答 1