In Java, byte = 8 bit, char = 16 bit

In C/C++, char = 8 bit

There is difference because Java uses Unicode, however C uses ASCII as basic character collection.

Java uses InputStream to read BYTE-DATA, to cover InputStream with InputStreamReader to read CHAR-DATA, to cover InputStreamReader with BufferedStream to read line of chars. So java have to recomprehend the byte infomation into char information and into line-chars information with a 2-step conversion.

Rembember the following:

size:   8 bit -> 16 bit -> line -> file

mode: byte -> char -> line -> file

read:  IS -> ISR -> BR -> String

write: OS -> OSW ->( *BW ->) PW -> String

Why do we have the parenthesized BW part?, see the official doc:(Java SE 8)

In general, a Writer sends its output immediately to the underlying character or byte stream. Unless prompt output is required, it is advisable to wrap a BufferedWriter around any Writer whose write() operations may be costly, such as FileWriters and OutputStreamWriters. For example,

 PrintWriter out
= new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));

will buffer the PrintWriter's output to the file. Without buffering, each invocation of a print() method would cause characters to be converted into bytes that would then be written immediately to the file, which can be very inefficient.

When reviewing some test programs that I wrote following the java tutorial, find something like:

 FileOutputStream out = new FileOutputStream("1.txt");
//Considering using the following method instead
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("1.txt"));

Checked Java SE 8 official API, that BOS method exists! Gee.. And, that's the exact usage of BOS.. Gee again...

Java R&W Related的更多相关文章

  1. python3 文件操作练习 r+ w+ a+ 的理解

    突然来一句:“慨然有经略四方之志” 文件操作三部曲:1.先用open打开 2.再写关闭  3.再回到中间写操作     为啥要刚打开就关闭 那是很容易望,所以先写上... 基本格式 f = open( ...

  2. SmartSql = Dapper + MyBatis + Cache(Memory | Redis) + ZooKeeper + R/W Splitting + ......

    SmartSql Why 拥抱 跨平台 DotNet Core,是时候了. 高性能.高生产力,超轻量级的ORM.156kb (Dapper:168kb) So SmartSql TargetFrame ...

  3. fopen特殊模式r+, w+, a+辨析

    fopen模式分两大类,即 TEXT模式:r, w, a, r+, w+, a+ BIN模式:rb, wb, ab, r+b, w+b, a+b 模式 读指针初始位置 写指针初始位置 模式用途 详细说 ...

  4. python r r+ w w+ rb 文件打开模式的区别

    # 只读模式with open ( "file.txt" ,'r' ) as f:        for line in f.readlines():                ...

  5. C语言中文件打开模式(r/w/a/r+/w+/a+/rb/wb/ab/rb+/wb+/ab+)浅析

    C语言文件打开模式浅析 在C语言的文件操作语法中,打开文件文件有以下12种模式,如下图: 打开模式  只可以读   只可以写  读写兼备 文本模式 r w a r+ w+ a+ 二进制模式 rb wb ...

  6. 008PHP文件处理——文件操作r w (用的比较多) a x(用的比较少) 模式 rewind 指针归位:

    <?php /** *文件操作r w (用的比较多) a x(用的比较少) 模式 rewind 指针归位: */ /*$a=fopen('a.txt','r'); echo fread($a,f ...

  7. 第九天- 文件操作 r w a 文件复制/修改

    文件操作简介:使用python来读写文件是非常简单的操作.我们使用 open() 函数来打开一个文件,获取到文件句柄.然后通过文件句柄就可以进行各种各样的操作了.根据打开⽅方式的不同能够执行的操作也会 ...

  8. python文件读写模式 --- r,w,a,r+,w+,a+,rb,wb

    要了解文件读写模式,需要了解几种模式的区别,以及对应指针 r : 读取文件,若文件不存在则会报错 w: 写入文件,若文件不存在则会先创建再写入,会覆盖原文件 a : 写入文件,若文件不存在则会先创建再 ...

  9. 转发:i p _ f o r w a r d函数

    转发:i p _ f o r w a r d函数到达非最终目的地系统的分组需要被转发.只有当 i p f o r w a r d i n g非零或当分组中包含源路由时,i p i n t r才调用实现 ...

随机推荐

  1. Java IO 节点流 ByteArrayInput/OutputStream

    Java IO 节点流 ByteArrayInput/OutputStream @author ixenos ByteArrayInputStream 包含一个内部缓冲区(字节数组byte[]),该缓 ...

  2. Codeforces Round #366 (Div. 2)_C. Thor

    C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  3. icheck.min.js 选中效果

    遍历所有 checkbox 如果是选中的用 绿色 如果未选中用 灰色 //check控件属性 $('input').each(function() { var self = $(this); var ...

  4. CentOS系统更换软件安装源aliyun的

    CentOS系统更换软件安装源第一步:备份你的原镜像文件,以免出错后可以恢复. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS ...

  5. IntelliJ IDEA 13.1.4新建java web项目

    打开软件

  6. python学习入门第一天总结

    虽然之前自己也看过许多关于python的视频,但一直没有动力与勇气,所以未能坚持且也没有学得这么深刻,这次希望通过python自动化培训,能够彻底改变自己,通过第一天的python学习,自己学到了许多 ...

  7. NOIP2002-普及组复赛-第三题-选数

    题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整 ...

  8. xfce chrome proxy

    Terminal 下命令行输入:google-chrome-stable %U --proxy-pac-url="http://127.0.0.1:16823/proxy_on.pac&qu ...

  9. angular项目——小小记事本2

    一,路由的规划. 需要模拟的页面有三个:all,active,conplete. 首先,写好铺垫需要的各种东西,重要的组件的引用等—— 这里我们会将index.html设为主页,将body.html加 ...

  10. wmic应用实例

    实例应用 1.磁盘管理 查看磁盘的属性 wmic logicaldisk list brief ::caption=标题.driveID=驱动器ID号.model=产品型号.Partitions=分区 ...