public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String filepath = "D:\\test.txt";
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filepath)));
String lin = "";
while (!(lin = br.readLine()).equals("exit")) {
bw.write(lin);
bw.newLine();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(bw != null){
bw.flush();
bw.close();
}
if(br != null)
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
温馨提示:答案为网友推荐,仅供参考