0
我試圖通過讀取用戶的輸入,直到達到某個終止符序列,但我無法弄清楚如何讓它終止,在控制檯中具有相應的文本框。將多行用戶輸入寫入文件
這裏是應該讀取輸入並將其寫入到文件的代碼:
try {
out = new BufferedWriter(new FileWriter("outagain.txt");
userInput = new Scanner(System.in);
String input;
while ((input = userInput.nextLine)) != null) {
out.write(input);
out.newLine();
input = null;
}
} finally {
if (userInput != null)
userInput.close();
if (out != null)
out.close();
有一些方法我可以捕捉來自用戶的轉義「碼」(即他們寫「:END」哪個突破了循環)還是有另一種方式來做到這一點?
預先感謝您。
是的,你可以通過設置,比如'一些終止字做到這一點。 –
那我該怎麼做呢?我試過了,但循環不會終止。 –