2016-12-24 56 views

回答

2

使用Files.readAllLines在原始文件中讀取,然後遍歷結果列表並使用Files.createFile根據要迭代的單詞創建新文件。

只要您在try-catches中添加以處理任何異常,類似下面的內容應該可以工作。

final List<String> lines = Files.readAllLines(Paths.get("C:/path/to/textFile.txt")); 

lines.forEach(line -> { 
    Files.createFile(Paths.get("C:/path/to/" + lines + ".txt")); 
}); 
+0

好主意,但解決方案是在Java 8 ..我認爲對於學習的目的(我認爲主題啓動器是新來的Java)需要自己學習與非常容易的Java 7實現。 – Reborn

0

試試這個

File f = new File(subjects.txt); 
Scanner s = new Scanner(f); 

wile(s.hasNext) 
{ 
    String name = s.nextLine(); 
    name += ".txt"; 
    PrintWriter outputFile= new PrintWriter(name); 
} 
相關問題