交作業交作業

来源:2-7 自由编程

胖達

2019-10-13 20:42:35

package com.imooc.file;

import java.io.File;
import java.io.IOException;

public class Monday {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		File file = new File("C:\\File");
		File file2 = new File(file,"Monday.docx");
		if(!file.exists()) {
			file.mkdir();
		}
		if(!file2.exists()) {
			try {
				file2.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("創建文件成功!");
			
	
		}
		if(file2.isFile()) {
			System.out.println("文件名稱:"+file2.getName());
			System.out.println("文件上一級目錄:"+file.getName());
		}
		if(file2.isFile()) {
			System.out.println("文件/目錄:這是一個文件");
		}else if(file2.isDirectory()) {
			System.out.println("文件/目錄:這是一個目錄");
		}
		if(file2.canRead()&&file2.canWrite()) {
			System.out.println("讀寫性:這個文件可以讀還可以寫");
		}else if(file2.canRead()) {
			System.out.println("讀寫性:這個文件可以讀");
		}else if(file2.canWrite()) {
			System.out.println("讀寫性:這個文件可以寫");
		}
	

	}

}


写回答

1回答

好帮手慕小班

2019-10-14

同学你好,复制运行同学的代码,运行效果是正确的哦!很棒哦!继续加油~

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

0

0 学习 · 11489 问题

查看课程

相似问题