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才调用实现 ...
随机推荐
- STL学习:STL库vector、string、set、map用法
本文仅介绍了如何使用它们常用的方法. vector 1.可随机访问,可在尾部插入元素:2.内存自动管理:3.头文件#include <vector> 1.创建vector对象 一维: (1 ...
- 安装asterisk
在centos6.5上: yum -y install lynx mysql-server mysql mysql-devel php php-mysql php-mbstring tftp-serv ...
- 用Bash脚本将Linux普通用户添加为系统管理员
将Linux普通用户添加为系统管理员在Gnome或KDE这样强大与完善的桌面环境下是非常简单的事情,一般来说在用户设置的对话框里就直接有相应选项.不过,出于简洁与高效的风格,自己目前并未使用这些高端但 ...
- hdu 1210 Eddy's 洗牌问题
Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于纸牌也有一定的研究,他在无聊时研究发现,如果他有2N张牌,编号为1,2,3..n,n+1,..2n.这也是 ...
- swift中JSon数据的处理
import UIKit class MainTabBarViewController: UITabBarController { override func viewDidLoad() { supe ...
- Virtual Drive Manager V1.3.2(小巧实用的虚拟光驱)绿色版
软件名称: Virtual Drive Manager V1.3.2(小巧实用的虚拟光驱)汉化绿色修正版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 ...
- Announcement
本来是习惯把每天的内容写在一个txt里. 似乎不符合要求.无论格式还是内容.于是转战blog. 事实上.有专业课学习加上马上考四级以及下学期可能的专业调整.此学期时间紧张. 能完成日常作业并掌握周课内 ...
- A - 小彭玉的扫荡食堂计划
A - 小彭玉的扫荡食堂计划 Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) ...
- 【ADT】链表的基本C语言实现
什么是抽象数据类型?首先,这一概念是软件开发人员在力求编写的代码健壮.易维护且可以复用的过程中产生的.英文是AbstractData Type.有人将其比作"抽象"的墙壁,&quo ...
- asp.net URL DES加密 什在URL中的使用
DES 加密 有时会有 + = 这些特殊字符串 Server.UrlDecode(Request["UserName"]) //能解决 = 号,但是 +号会变成空格 HttpUt ...