여기까지 제가 지금까지 가지고 있습니다. 그것은 1.txt 장을 성공적으로 읽고 그것을 book.txt에 넣습니다.하지만 두 장을 더 받아 들여야합니다. 그리고 이것은 제가 잃어버린 곳입니다. 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(); } }