我只是想反转从输入中收到的行,但是每次运行代码时, output.txt 文件都是空的。我错过了什么?它对我来说似乎大部分都是正确的,甚至是递归段落。
谢谢
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
public class ReverseLines {
public static BufferedReader input;
public static PrintWriter output;
public static void main(String[] args) throws Exception{
input = new BufferedReader(new FileReader(args[0]));
output = new PrintWriter(new FileWriter(args[1]));
reverse(input, output);
}
public static void reverse( BufferedReader input, PrintWriter output)
throws Exception {
String line = input.readLine();
if(line != null) {
reverse (input, output);
output.println(line);
}
}
}