实例
-
复制文件、复制文件流
https://blog.csdn.net/LawssssCat/article/details/103053750 -
JavaIO BufferedReader和BufferedWriter介绍和实例
https://blog.csdn.net/qq_21808961/article/details/81561464 -
java追加文本到文件末尾
BufferedWriter out = null ;
try {
out = new BufferedWriter( new OutputStreamWriter(
new FileOutputStream(file, true )));
out.write(conent);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
后话
继承结构
<mark>in/out</mark>相对于程序而言的输入(读取)和输出(写出)的过程。
在Java中,根据处理的数据单位不同,分为<mark>字节流</mark>和<mark>字符流</mark>
java.io包:
File
<mark>字节流:针对二进制文件</mark>
InputStream
–FileInputStream
–BufferedInputStream
–ObjectInputStream
OutputStream
–FileOutputStream
–BufferedOutputStream
–ObjectOutputStream
<mark>字符流:针对文本文件。</mark>
Writer
–BufferedWriter
–OutputStreamWriter
Reader
–BufferedReader
–InputStreamReader
–PrintWriter/PrintStream
读写容易发生乱码现象,在读写时最好指定编码集为utf-8
流的概念
数据的读写抽象成数据,在管道中流动。
- 流只能单方向流动
- 输入流用来读取in
- 输出流用来写出Out
- 数据只能从头到尾顺序的读写一次