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呢?