这是我到目前为止。它成功读取第1.txt章节并将它放入book.txt中,但是,我需要让它接受2个章节,这是我无所适从的地方。有没有一种方法可以使用FileReader方法来读取多个文本文件?有没有一种方法可以使用FileReader方法来读取多个文本文件?
import java.io.*; import java.util.*; public class CatFiles { public static void main(String[] args) throws FileNotFoundException, IOException { File compiledChapters = new File("Book.txt"); if(!compiledChapters.exists()) { compiledChapters.createNewFile(); } FileReader myReader = new FileReader("chapter 1.txt"); Scanner myScanner = new Scanner(myReader); PrintWriter myWriter = new PrintWriter("Book.txt"); while(myScanner.hasNextLine()) { String textLine = myScanner.nextLine(); myWriter.println(textLine); }
myReader.close(); myWriter.close(); } }