62,621
社区成员
发帖
与我相关
我的任务
分享
BufferedWriter f = null;
boolean a = true;
try {
f = new BufferedWriter(new FileWriter("D:/file.text"));
while (a) {
Scanner reader = new Scanner(System.in);
String s1 = null;
s1 = reader.nextLine();
System.out.println(s1);
if (s1.equals("exit")){
a=false;
}
f.write(s1);
}
f.flush();
f.close();
} catch (IOException e) {
e.printStackTrace();
}