import java.io.*;class File_Manage{ public static void main(String[] args) throws IOException{ File dir_Books = new File("C:/Books"); File file_Book1 = new File(dir_Books, "Book1.txt"); if(!dir_Books.exists()){ System.out.print(dir_Books.getName()+"是否建立成功? "); System.out.println(dir_Books.mkdirs()); } else System.out.println(dir_Books.getName() + "已存在"); if(!file_Book1.exists()){ System.out.print(file_Book1.getName()+"是否建立成功? "); System.out.println(file_Book1.createNewFile()); //file.deleteOnExit(); } else System.out.println(file_Book1.getName() + "文件已存在"); File file_Book2 = new File(file_Book1.getParent(), "Book2.txt"); System.out.println(file_Book1.getName() + "改名为" + file_Book2.getName()); System.out.print("是否修改成功? "); System.out.println(file_Book1.renameTo(file_Book2)); System.out.print(file_Book2.getName() + "是否删除成功? "); System.out.println(file_Book2.delete()); System.out.print(dir_Books.getName() + "是否删除成功? "); System.out.println(dir_Books.delete()); }}
添加回答
举报
0/150
提交
取消