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. Talking Ben App砸壳记

    需求: 导出Talking Ben app的头文件 实施: 1)准备材料: 越狱IOS设备一部,并安装Talking Ben游戏 IOS设备上安装open SSH IOS设备的/usr/bin 中安装 ...

  2. GUI自绘_其中左边树状菜单控件风格灵感来源于城市博物馆的壁灯效果。

    GUI DEMO 下面都是去年做的演示DEMO,到目前为止,除了专门做界面库的公司,暂时还没有看到别人做的效果比我这个更好的. 下图在第一张图中有个错误,看出来了没有呢? 就是项目核算那儿,不应该是B ...

  3. Leetcode 073 Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...

  4. C的指针,真的很经典

    工作以后,一直使用C++,也做过Objective C,各种类的方法封装得很好,使用很简单,今天偶尔翻看一下 严蔚敏 的 <数据结构>,第一个程序demo就看了半天,一是由于demo的变量 ...

  5. chapter 13_2 关系类、库定义的元方法

    元表还可以指定关系操作符的含义,元方法为__eq ,__lt(小于) ,__le(小于等于). 而其它3个关系操作符则没有单独的元方法,Lua会 把a ~= b 转化为not(a == b) 将a&g ...

  6. 29.编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数 loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个 类都有构造方法和输出相关数据的方法。最后,写一个测试类来测试这些类的功 能。

    //Vehicle类 package d922A; public class Vehicle { private int wheels; private double weight; Vehicle( ...

  7. Shell grep 和正则

    在grep中正则有三种模式, 分别是基础(-G), 扩展(-E)和Perl(-P)模式 basic 模式 不支持\d, 支持\w \s \b. ?, +, {, |, (, and ) 在basic ...

  8. MyBatis 多表联合查询,字段重复的解决方法

    MyBatis 多表联合查询,两张表中字段重复时,在配置文件中,sql语句联合查询时使用字段别名,resultMap中对应的column属性使用相应的别名: <resultMap type=&q ...

  9. js对象,类

    js闭包网站:http://www.cnblogs.com/qieguo/p/5457040.html 有权访问另一个函数作用域内变量的函数都是闭包. 这里 inc 函数访问了构造函数 a 里面的变量 ...

  10. power oj/2360/Change

    题目链接[https://www.oj.swust.edu.cn/problem/show/2360] 题意:给出两个四位数A.B,目地是用最少的步骤使A变成B.变换规则如下:1.相邻的两位数可以交换 ...