學習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.uj5u.com/houduan/230597.html
標籤:Java
下一篇:Java靜態變數和實體變數
