字节流和字符流的区别
2016-07-27 14:46
375 查看
如果数据流中最小的数据单元是字节,那么称这种流为字节流;如果数据流中最小的数据单元是字符,那么称这种流为字符流
1. 字节流(byte)
- InputStream、OutputStream
- FileInputStream、FileOutputStream
示例代码:
2. 字符流(char)
- Reader、Writer
附:实际上字节流在操作时本身不会用到缓冲区(内存),是文件本身直接操作的,而字符流在操作时使用了缓冲区,通过缓冲区再操作文件,如图12-6所示。原文链接
1. 字节流(byte)
- InputStream、OutputStream
- FileInputStream、FileOutputStream
示例代码:
/** * 字节流 写操作 * @throws FileNotFoundException */ public static void byteWriter() throws FileNotFoundException{ File f=new File("g:"+File.separator+"test.txt"); OutputStream out=new FileOutputStream(f); String s="test..."; byte[] bytes=s.getBytes(); try { out.write(bytes); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
2. 字符流(char)
- Reader、Writer
附:实际上字节流在操作时本身不会用到缓冲区(内存),是文件本身直接操作的,而字符流在操作时使用了缓冲区,通过缓冲区再操作文件,如图12-6所示。原文链接
相关文章推荐
- Java字符流与字节流区别与用法分析
- 详解Java中字符流与字节流的区别
- java实现将字符串转化为二进制输出
- IO流(三)_File类_字节流与字符流
- Java IO
- 【学习日记】有关java的IO的知识点总结
- 替换空格(面试题4)
- IO应用
- Java流操作有关的类或接口
- 字节流与字符流
- 黑马程序员--------java IO流 Reader、Writer、InputStream、OutputStream
- IO流
- 黑马程序员_IO流
- 黑马程序员--IO流(1)
- 黑马程序员--IO流(2)
- 黑马程序员--字符流与字节流区别
- 黑马_blog5_IO流
- 黑马程序员 <梦想之旅 >转换流
- Java的字节流和字符流
- 黑马程序员——Java基础--IO流(一)