批量快速生成员工文件夹工具

  学习Java IO操作,写了一个简单的快捷生成员工文件夹的功能小程序。

  代码如下:

 1 public class Main2 {
 2     public static void test() {
 3         ArrayList<String> list = new ArrayList<String>();
 4         try {
 5             BufferedReader bufferRder = new BufferedReader(
 6                     new InputStreamReader(new FileInputStream("name.txt"), "UTF-8"));
 7             String str = bufferRder.readLine();
 8             while (str != null) {
 9                 list.add(str);
10                 str = bufferRder.readLine();
11             }
12             for (int listIndex = 0; listIndex <= list.size() - 1; listIndex++) {
13                 System.out.println(list.get(listIndex));
14                 String createFile = "NewFile\" + list.get(listIndex);
15                 File file = new File(createFile);
16                 if (!file.exists()) {
17                     file.mkdirs();
18                 }
19             }
20 
21         } catch (FileNotFoundException e) {
22             e.printStackTrace();
23         } catch (IOException e) {
24             e.printStackTrace();
25         }
26     }
27 
28     public static void main(String[] args) {
29 
30         test();
31 
32     }
33 }

  执行过程十分简单,把需要创建员工文件夹的员工姓名一行一行地保存到name.txt文档中,然后把程序放到跟name.txt文档相同目录下,然后双击运行.jar文件即可。

运行后,当前目录下会生成一个NewFile文件夹,文件夹内包含有所有生成好的员工姓名文件夹。

  需要注意:     1、name.txt文档名不能随意更改,否则.jar程序不识别加载文件,从而无法生成目标文件夹。

         2、因为程序结构相对简单,没有非常严谨全面的字符过滤功能,所以不建议在文档中输入过多特殊字符。

 

 name.txt和.jar文件需放在同一目录下

 

姓名用回车分隔

  

 双击生成员工文件夹目录

 

  生成好的员工文件夹

 

  下载链接:https://rere.lanzous.com/iM19Xj2l3te

  个人Java学习阶段小程序,不存在任何报毒情况,请放心食用!

原文地址:https://www.cnblogs.com/moegarn/p/14089232.html