首页 > 其他 > 详细

在d盘中创建一个文件夹 在文件夹里创建三个txt文本

时间:2019-03-24 01:35:07      阅读:303      评论:0      收藏:0      [点我收藏+]
 1 import java.io.File;
 2 import java.io.IOException;
 3 
 4 public class FileDemo {
 5     public static void main(String[] args) {
 6         // 抛除异常IOEcxception
 7         try {
 8             fun();
 9         } catch (IOException e) {
10             e.printStackTrace();
11         }
12     }
13     public static void fun() throws IOException {
14         // 在d盘创建一个文件夹aaa   madir()创建文件夹目录
15         File file = new File("d:\\aaa");
16         boolean mkdir = file.mkdir();
17         System.out.println(mkdir);
18         // 在d盘的文件夹aaa里面创建三个文本   createNewFile()创建文件
19         File file1 = new File("d:\\aaa\\aaa.txt");
20         boolean newFile1 = file1.createNewFile();
21         System.out.println(newFile1);
22         File file2 = new File("d:\\aaa\\bbb.txt");
23         boolean newFile2 = file2.createNewFile();
24         System.out.println(newFile2);
25         File file3 = new File("d:\\aaa\\ddd.txt");
26         boolean newFile3 = file3.createNewFile();
27         System.out.println(newFile3);
28 
29         // 多创建了一个ccc.txt文本
30         // 删除文件夹内的ccc.txt文本
31         File file4 = new File("d:\\aaa\\ccc.txt");
32         boolean delete = file4.delete();
33         System.out.println(delete);
34 
35         // 遍历文件夹aaa内的三个文本   list() 遍历
36         File file5 = new File("d:\\aaa");
37         String[] list = file5.list();
38         for(String i:list){
39             System.out.println(i);
40         }
41     }
42 }

打印结果   再看看d盘有没有成功创建文件
技术分享图片

在d盘中创建一个文件夹 在文件夹里创建三个txt文本

原文:https://www.cnblogs.com/zhangmenghui/p/10586152.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!