IO流的操作规律。

1.  明确源和目的

源代表输入流: InputStream, Reader

目的代表输出流: OutputStream, Writer

2. 操作数据是否纯文本

纯文本:字符流

非纯文本: 字节流

键盘输入基本模型

 BufferedReader br = new BufferedReader((new InputStreamReader(System.in)));

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

从文件读取

BufferedReader br = new BufferedReader((new InputStreamReader(new FileInputStream("xxx.txt")));

存入到文件

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("xxx.txt")));

  String line;

while((line=br.readLine())!=null)

{

if(line.equals("over"))

break;

bw.write(line);

bw.newLine();

bw.flush();

}

上一篇:【Spring IoC】Spring Bean(三)


下一篇:= =用createJS写个flyppyPeople