首页 新闻 搜索 专区 学院

FileReader的read读取数据为何打印不出来

0
悬赏园豆:5 [待解决问题]

package com.example.demo002.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

public class test {
private static final Logger logger = LoggerFactory.getLogger(test.class);
public static void main(String[] args) {
File file1 = new File("D:\study\test1.txt");
String pathStr = "D:" + File.separator+"study"+ File.separator+"test2.txt";
File file2 = new File(pathStr);
System.out.println(file1.toString());
System.out.println(pathStr);
FileOutputStream outputStream = null;
FileInputStream inputStream = null;
FileReader reader = null;
FileWriter writer = null;
byte[] bytesLen = new byte[3];
try {

        // 2.字符流
        System.out.println("===========字符流==========");
        writer = new FileWriter(file2);
        reader = new FileReader(file2);
        writer.write(97);
        int read2 = reader.read();
        System.out.println("第一次读取" +  (char)read2);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            outputStream.close();
            inputStream.close();
            writer.close();
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

}

输出:
=字符流
第一次读取￿

为何输出的结果不a呢?

lanto_liang的主页 lanto_liang | 初学一级 | 园豆:8
提问于:2021-05-30 15:42
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册