Java R&W Related
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的更多相关文章
- python3 文件操作练习 r+ w+ a+ 的理解
突然来一句:“慨然有经略四方之志” 文件操作三部曲:1.先用open打开 2.再写关闭 3.再回到中间写操作 为啥要刚打开就关闭 那是很容易望,所以先写上... 基本格式 f = open( ...
- SmartSql = Dapper + MyBatis + Cache(Memory | Redis) + ZooKeeper + R/W Splitting + ......
SmartSql Why 拥抱 跨平台 DotNet Core,是时候了. 高性能.高生产力,超轻量级的ORM.156kb (Dapper:168kb) So SmartSql TargetFrame ...
- fopen特殊模式r+, w+, a+辨析
fopen模式分两大类,即 TEXT模式:r, w, a, r+, w+, a+ BIN模式:rb, wb, ab, r+b, w+b, a+b 模式 读指针初始位置 写指针初始位置 模式用途 详细说 ...
- python r r+ w w+ rb 文件打开模式的区别
# 只读模式with open ( "file.txt" ,'r' ) as f: for line in f.readlines(): ...
- C语言中文件打开模式(r/w/a/r+/w+/a+/rb/wb/ab/rb+/wb+/ab+)浅析
C语言文件打开模式浅析 在C语言的文件操作语法中,打开文件文件有以下12种模式,如下图: 打开模式 只可以读 只可以写 读写兼备 文本模式 r w a r+ w+ a+ 二进制模式 rb wb ...
- 008PHP文件处理——文件操作r w (用的比较多) a x(用的比较少) 模式 rewind 指针归位:
<?php /** *文件操作r w (用的比较多) a x(用的比较少) 模式 rewind 指针归位: */ /*$a=fopen('a.txt','r'); echo fread($a,f ...
- 第九天- 文件操作 r w a 文件复制/修改
文件操作简介:使用python来读写文件是非常简单的操作.我们使用 open() 函数来打开一个文件,获取到文件句柄.然后通过文件句柄就可以进行各种各样的操作了.根据打开⽅方式的不同能够执行的操作也会 ...
- python文件读写模式 --- r,w,a,r+,w+,a+,rb,wb
要了解文件读写模式,需要了解几种模式的区别,以及对应指针 r : 读取文件,若文件不存在则会报错 w: 写入文件,若文件不存在则会先创建再写入,会覆盖原文件 a : 写入文件,若文件不存在则会先创建再 ...
- 转发: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才调用实现 ...
随机推荐
- Java Object 对象拷贝答疑
Java Object 对象拷贝答疑 @author ixenos 摘要:在对象的clone过程需要注意的几点.关于关键字this.super 关于clone[对象拷贝] 在实际编程过程,有时候我们会 ...
- 用makecert.exe生成一个自签名的证书
makecert.exe不用去找,安装VS2008后,在开始菜单相应的路径找到该命令提示符:Microsoft Visual Studio 2008/Visual Studio Tools/Visua ...
- lua 中操作系统库
time 和 date 两个函数在lua中实现所有的时钟查询功能. 函数time在没有参数时返回当前时钟的数值.(在许多操作系统中,该数值是距离某个特定时间的秒数). date是time的一种“反函数 ...
- informix建临时表索引
对于特殊字段,比如外键,主键,在不知道外键主键名的情况下,需要如下操作select constrname from sysconstraints where constrtype='R' and ta ...
- 转Rollback后undo到底做了些什么?
转自:http://biancheng.dnbcw.info/oracle/309191.html Rollback后undo到底做了些什么? 从概念上讲,undo正好与redo相对.当你对数据执行修 ...
- matlab mse函数
mse是检验神经网络算法的误差分析; mse是平均平方误差性能函数,是网络性能函数.平方误差就是指误差的平方.
- C# 二维数组和集合
本次课我主要学习了二维数组和集合的部分内容. 在二维数组的部分中,我主要学习了二维数组的定义方法:int [,] array=new int [4,2];做了一个小练习:用二维数组打印自己的姓氏. s ...
- PHP中require和include的区别
include()与require()的功能相同 include(include_once) 与 require(require_once)都是把把包含的文件代码读入到指定位置来,但是二者再用法上有区 ...
- spring框架--IOC容器,依赖注入
思考: 1. 对象创建创建能否写死? 2. 对象创建细节 对象数量 action 多个 [维护成员变量] service 一个 [不需要维护公共变量] dao 一个 [不需要维护 ...
- android基础知识点复习之短信发送
界面布局: activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an ...