IO_02
2013-10-03 10:18
225 查看
IO流(InputStream,OutputStream)抽象类
Java中的IO流是实现输入/输出的基础 EOF == End Of File ==-1;
输入基本方法:
int b = in.read()读取一个byte无符号填充到int低八位,-1是EOF
in.read(byte[] buf)读取数据填充到buf中 in.read(byte[] buf, int start, int size) in.skip(long n) in.close()
输出基本方法:
out.write(int b)
写出一个byte到流b的低八位写出
out.write(byte[] buf) 将缓冲区buf都写入到流 out.write(byte[] buf,int start,int size) out.flush()清理缓冲,out.close();
IO工具类 IOUtils.java
printHex()方法,读取文件并且安装HEX输出,每10byte为一行,没输出一行,则换行
复制文件,从输入流读取写出输出流
FileInputStream和FileOutputStream
DataOutputStream和DataInputStream是对"流"功能的扩展,提供了基本数据类型的序列化与反序列化
BufferedInputStream和BufferedOuputStream为IO操作提供了缓冲区,一般打开文件进行读写时都加上缓冲流,提高IO性能
仅使用FOS的write方法,相当于一滴水一滴水的转移;使用DOS的write方法,相当于一瓢一瓢的转移;使用BOS的write方法相当于从DOS一瓢一瓢放入桶BOS中,再从桶BOS中倒入另一个缸,性能提高
Java的文本(char)是16位无符号整数,是字符的unicode编码,文件时byte by byte ...的数据序列
文本文件是字符序列安装某种编码方案序列化为byte的存储结果
字符流(Reader Writer)
字符的处理:一次处理一个字符
字符的底层仍是基本的字节流
字符流的基本实现:InputStreamReader-->byte--char 编码解析;OutputStreamWriter -->char--byte 编码处理
字符流的过滤器
是字符读写的功能扩展,方便文本的读写操作
BufferedReader:readLine()一次读一行 ;PrintWriter:println() 一次打印一行
读一个文本文件
写出一个文本文件 类似
Java中的IO流是实现输入/输出的基础 EOF == End Of File ==-1;
输入基本方法:
int b = in.read()读取一个byte无符号填充到int低八位,-1是EOF
in.read(byte[] buf)读取数据填充到buf中 in.read(byte[] buf, int start, int size) in.skip(long n) in.close()
输出基本方法:
out.write(int b)
写出一个byte到流b的低八位写出
out.write(byte[] buf) 将缓冲区buf都写入到流 out.write(byte[] buf,int start,int size) out.flush()清理缓冲,out.close();
IO工具类 IOUtils.java
printHex()方法,读取文件并且安装HEX输出,每10byte为一行,没输出一行,则换行
复制文件,从输入流读取写出输出流
public static void copy(String src, String dest) throws IOException{ InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buf = new byte[1024*512]; int count; while((count=in.read(buf))!=-1){//EOF out.write(buf, 0, count); } in.close(); out.close(); }
FileInputStream和FileOutputStream
DataOutputStream和DataInputStream是对"流"功能的扩展,提供了基本数据类型的序列化与反序列化
BufferedInputStream和BufferedOuputStream为IO操作提供了缓冲区,一般打开文件进行读写时都加上缓冲流,提高IO性能
仅使用FOS的write方法,相当于一滴水一滴水的转移;使用DOS的write方法,相当于一瓢一瓢的转移;使用BOS的write方法相当于从DOS一瓢一瓢放入桶BOS中,再从桶BOS中倒入另一个缸,性能提高
Java的文本(char)是16位无符号整数,是字符的unicode编码,文件时byte by byte ...的数据序列
文本文件是字符序列安装某种编码方案序列化为byte的存储结果
字符流(Reader Writer)
字符的处理:一次处理一个字符
字符的底层仍是基本的字节流
字符流的基本实现:InputStreamReader-->byte--char 编码解析;OutputStreamWriter -->char--byte 编码处理
字符流的过滤器
是字符读写的功能扩展,方便文本的读写操作
BufferedReader:readLine()一次读一行 ;PrintWriter:println() 一次打印一行
读一个文本文件
String file = "demo.txt"; BufferedReader br = new BufferedReader(new FileReader(file)); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
写出一个文本文件 类似
相关文章推荐
- IO_02_字符流的缓冲区
- boost.asio 学习笔记02——io_service类
- 黑马程序员_IO_02
- JAVA高级视频02_IO输入与输出日记2(02-04到05)
- boost.asio 学习笔记02——io_service类
- java io系列02之 ByteArrayInputStream的简介,源码分析和示例(包括InputStream)
- ZigBee TI ZStack CC2530 3.11 IO口02-外部中断
- [零基础学JAVA]Java SE应用部分-28.Java IO操作(02) 推荐
- IO-02. 整数四则运算(10)
- 工控随笔_02_西门子_WinCC的IO域利用C脚本返回值
- IO-02 整数四则运算
- JAVA高级视频02_IO输入与输出日记3(02-06到10)
- IO-02. 整数四则运算(10)
- JAVA高级视频02_IO输入与输出日记4(02-11到12)
- 02_checkio_House_Passworld
- java io系列02之 ByteArrayInputStream的简介,源码分析和示例(包括InputStream)
- APUE读书笔记-14高级输入输出-02非阻塞IO
- 黑马程序员_日记02(IO)
- IO-02. 整数四则运算