public class InputStreamReaderDemo {
public static void main(String[] args) throws IOException {
// 数据源 : 字节流转换成字符流 获取键盘输入
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//目的地
BufferedWriter bw = new BufferedWriter(new FileWriter("demo.txt"));
//数据读取
String line = null;
while((line = br.readLine()) != null) {
/* if("886"==(line)) { // 假设键盘输入886 用== 就不能结束程序.用equals就可以
break;
}*/
if("886".equals(line)) {
break;
} else{
bw.write(line);
bw.newLine();
bw.flush();
}
}
// 释放资源
br.close();
bw.close();
}
} |