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的更多相关文章
随机推荐
- autofac中文文档
https://autofaccn.readthedocs.io/zh/latest/index.html
- Alsa aplay S8 U8 S16_LE S16_BE U16_LE U16_BE格式
举个例子 aplay -r 16000 -f S16_LE -D hw:0,0 -c 2 -d 3 ~/Private/Private_Tools/02_ALSA_Learning/left_1k_r ...
- python网页爬虫开发之六-Selenium使用
chromedriver禁用图片,禁用js,切换UA selenium 模拟chrome浏览器,此时就是一个真实的浏览器,一个浏览器该加载的该渲染的它都加载都渲染,所以爬取网页的速度很慢.如果可以不加 ...
- Chapter 5 数组:为什么很多编程语言种数组都是从0开始编号?
如何实现随机访问? 线性表:数组,队列,链表,栈 非线性表:树,图 总结:数组用一块连续的内存空间,来存储相同类型的一组数据,最大的特点就是支持随机访问,但插入,删除操作也因此变得比较低效,平均情况时 ...
- 团队第一次 # scrum meeting
github 本此会议项目由PM召开,召开时间为4-1日晚上9点 召开时长30分钟 任务表格 袁勤 重新搭建原本的项目 https://github.com/buaa-2016/BuaaPhyLabB ...
- JS数据类型的判断
在 ECMAScript 规范中,共定义了 7 种数据类型,分为 基本类型 和 引用类型 两大类,如下所示: 基本类型:String.Number.Boolean.Symbol.Undefine ...
- win10 64位,家庭版,C++,ini配置说明
#include<windows.h> #include<iostream> #include <atlstr.h> using namespace std; ...
- python大法好—模块 续
1.sys模块 sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传递参数. sys.exit([arg]): 程序中间的退出,arg=0为正常退出. sys.getdefaulten ...
- CPU与内存互联的架构演变
随着计算机中CPU核数目的增加,传统的UMA(unifonn memory access)架构由于对关键硬件(如中央内存控制器)的竞争加剧出现了性能上的瓶颈,即扩展性不强.而NUMA架构则以其良好的可 ...
- Rabbitmq(6) 主题模式
* 匹配1个 # 匹配所有 发送者: package com.aynu.bootamqp.service; import com.aynu.bootamqp.commons.utils.Amqp; i ...