I/O dempo
标准读取写入
package io_stream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FilePwd {
public static void main(String[] args) {
// TODO Auto-generated method stub
fileIn();
}
public static void fileIn() {
// FileInputStream r = null;
// FileOutputStream w = null;
try (BufferedInputStream r = new BufferedInputStream(new FileInputStream("src/file/file02.txt"));
BufferedOutputStream w =new BufferedOutputStream(new FileOutputStream("src/file/pwd.txt")))
{
byte[] bytes = new byte[20];// 定义每次读取字节数量
int temp;
while ((temp = r.read()) != -1) {// 判断是否读完
System.out.println(temp);
w.write(temp);// 写入文件
w.write(temp^77);// 文件加密,解密时异或相同的数字即可
//System.out.println("写入成功");
}
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
.read()返回的是整数类型,.write()整数类型时,写入对应ascll码的字符,并且只能写入整数类型和char类型
字符流:每次读取一个字符FileReader fr = new FileReader("word.txt");
缓冲字符流:每次读取一行字符,
字符流不能用于非文本文件,如图片
结构图

包装类
- 包装字节流为字符流
InputStreamReader isr = new InputStreamReader(System.in); // 将标准字节输入流包装成字符输入流, system.in为标准字节输入流
InputStreamReader isr1 = new InputStreamReader(new FileInputStream("a")); // 将标准字节输入流包装成字符输入流
- 包装普通流为高效缓冲流
字节:BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("a"));
字符:BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 包装成缓冲字符输入流
I/O dempo的更多相关文章
随机推荐
- docker stats监控容器资源消耗
在容器的使用过程中,如果能及时的掌握容器使用的系统资源,无论对开发还是运维工作都是非常有益的.幸运的是 docker 自己就提供了这样的命令:docker stats. 默认输出 docker sta ...
- Python【每日一问】04
问:a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],求出列表a中所有奇数并构造新列表 答: 利用列表的元素下标遍历列表 a = [1, 2, 3, 4, 5, 6, 7, 8 ...
- React实现了一个鼠标移入的菜单栏效果
<!DOCTYPE html><html> <head> <meta charset="UTF-8" /> <title> ...
- android 开发 View _10_ Path之基本操作
转载地址:http://www.gcssloop.com/customview/Path_Basic/ 安卓自定义View进阶-Path之基本操作 在上一篇Canvas之图片文字中我们了解了如何使用C ...
- Ubuntu 14.04 tomcat配置
在tomcat-users.xml中添加了以下代码即可 <role rolename="tomcat"/> <role rolename="role1& ...
- python——数字问题之_ 变量
在交互模式中,最后被输出的表达式结果被赋值给变量 _ ._ 变量应被用户视为只读变量 >>> a=12/2.3 >>> b=1.2 >>> a*b ...
- maven的tomcat插件问题
在dependence中不用加tomcat的jar, 记得在plugin中加入tomcat插件就行. 否则会出问题.
- JQ attr prop 区别
解决方法:使用prop属性代替attr属性 一.Attr除 checked, selected, 或 disabled状态属性外,其余的属性均可用attr()设置和修改.$("img&quo ...
- python学习记录
学习python中······· 今天写了个装饰器用来登录用,用户名和密码是存在文件里的,涉及到了装饰器和带参数的装饰器 文件里的内容如下 {"liming": 123456} { ...
- ubuntu安装gitlab-ci-runner、注册
首先信任 GitLab 的 GPG 公钥: curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - ...