我正在从输入文件中读取内容。我想将其写入另一个文件。但是,当输入行中有更多行时,如果输入“ enter”,则不会将此输入写入输出文件。有人知道如何解决此问题吗?
我的代码:
public static void main(String[] args) throws IOException
{
Scanner scanner = new Scanner(System.in);
System.out.println("Give the input filename");
File inputFile = new File(scanner.next());
InputStreamReader reader = new InputStreamReader(new FileInputStream(inputFile));
System.out.println("Give the output filename");
File outputFile = new File(scanner.next());
OutputStreamWriter writer;
try {
writer = new OutputStreamWriter(new FileOutputStream(outputFile));
int c;
while ((c = reader.read()) >= 0) {
writer.write((char) c);
}
reader.close();
writer.close();
} catch (FileNotFoundException e) {
System.out.println("File is not found!");
}
scanner.close();
}