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的更多相关文章
随机推荐
- LeetCode【83. 删除排序链表中的重复元素】
我最开始的程序是 但是结果
- 如何查看安装python和numpy的版本
命令行下查看python和numpy的版本和安装位置 1.查看python版本 方法一: python -V 注意:‘-V‘中‘V’为大写字母,只有一个‘-’ 方法二: python --versio ...
- normalization正规化
用到sklearn模块 from sklearn import preprocessing用preprocessing.scale正规化 print(preprocessing.scale(a))
- 根据日志分析异常:There is already 'XXX' bean method
问题代码: @Slf4j @Api(value = "paymentOrderController", description = "PaymentOrderContro ...
- Servlet】(2)有关Servlet实现的几个类:GenericServlet、HttpServlet、ServletConfig、ServletContext
一.GenericServlet 1.所有的成员方法: 1.在javaWeb项目中: 2.web.xml <?xml version="1.0" encoding=" ...
- 最强Hibernate搭建文章(转)
Hibernate优势: 1.Hibernate对JDBC访问数据库的代码做了轻量级的封装,大大简化了数据访问的层的重复性代码,并却减少了内存消耗,加快了运行效率. 2.Hibernate是一个基于J ...
- 如何使用 Visual C# .NET 处理 Excel 事件
事件处理概述 Visual C# .NET 使用委派处理来自组件对象模型 (COM) 服务器的事件.委派是 Microsoft Visual Studio .NET 中的一个新概念.对于 COM 事件 ...
- leetcode239
class Solution: def maxSlidingWindow(self, nums: 'List[int]', k: int) -> 'List[int]': n = len(num ...
- Linux输入子系统详解
input输入子系统框架 linux输入子系统(linux input subsystem)从上到下由三层实现,分别为:输入子系统事件处理层(EventHandler).输入子系统核心层(Input ...
- poi横纵动态导入
dao层 <insert id ="saveInTarget" parameterType="java.util.List" > INSERT IN ...