标准读取写入

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的更多相关文章

随机推荐

  1. RHEL7调图形化

    RHEL7调图形化 作者:Eric 微信:loveoracle11g 1.将默认的运行级别修改为"多用户,无图模式" [root@server ~]# ln -sf /lib/sy ...

  2. Chapter 5 数组:为什么很多编程语言种数组都是从0开始编号?

    如何实现随机访问? 线性表:数组,队列,链表,栈 非线性表:树,图 总结:数组用一块连续的内存空间,来存储相同类型的一组数据,最大的特点就是支持随机访问,但插入,删除操作也因此变得比较低效,平均情况时 ...

  3. Sqlserver 2016 R Service环境安装的各种错误(坑)解决办法

    相信很多朋友都会慕名Sqlserver 2016的R语言功能,将自己的数据库升级到Sqlserver 2016,但是当你安装完Sqlserver 2016的R语言组件之后,你会发现并不能直接使用,比如 ...

  4. cookie与session的区别是什么

    cookie与session的区别有:cookie以文本格式存储在浏览器上,存储量有限:而会话存储在服务端,可以无限量存储多个变量并且比cookie更安全 在php中可以指定站点的访问者信息存储在se ...

  5. linux面试题-基础题1

    第1章 基础题1 1.1 在装系统创建Linux分区时,一般至少需要创建两个分区( ) A.FAT.NTFS   B. /usr.swap    C. /boot.swap  D.swap./ 1.2 ...

  6. tomcat 部署swagger 请求到后端乱码

    问题: @ApiOperation(value = "", notes = "查看关键词列表") @ResponseBody @RequestMapping(v ...

  7. leetcode32

    class Solution { public: int longestValidParentheses(string s) { ; stack<int> st; ; i < n; ...

  8. Python-反射getattr的应用

    login.py #!/usr/bin/dev python# coding:utf-8 def index(): print u'欢迎访问xx网站首页' def login(): print u'登 ...

  9. 第三篇、Python函数

    1.函数和过程的定义: 1) 函数定义:函数是逻辑结构化和过程化的一种编程方法. 2) 过程定义:过程就是简单特殊没有返回值的函数. 当一个函数/过程没有使用return显示的定义返回值时,pytho ...

  10. python 列表、元组、字典的区别

    区别: 相互转换:https://www.cnblogs.com/louis-w/p/8391147.html 一.列表 list [1,[2,'AA'],5,'orderl'] 1.任意对象的有序集 ...