這個程序應該接受信息(通過文件重定向),並應該輸出它給出的內容,包括空格,而不是最後一行。它應該是完全一樣的,沒有任何區別。我的教授說這是錯誤的。這個應該輸出確切輸入的java程序有什麼問題?
import java.io.*;
public class driver_proj0{
public static void main(String[] args){
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
String lineInput = "";
try {
lineInput = f.readLine();
}
catch (IOException e){
e.printStackTrace();
}
while (lineInput != null){
System.out.print(lineInput); // I just want to print it without a new line out for now
try {
lineInput = f.readLine();
}
catch (IOException e){
e.printStackTrace();
}
if (lineInput != null){
System.out.println();
}
} // end while
} //end main
}// end class
你必須使用基於行的緩衝嗎?爲什麼你不能只是在許多字節中啜泣,並再次吐出它們呢?你最後'lineinput!= null' println可能是什麼東西在扔掉。 –
什麼是錯的?你得到什麼輸入和輸出? – yogidilip
你問過你的教授嗎? – lrnzcig