package iotest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class BufferedReaderDemo {
public static void main(String[] args) {
File file = new File("d://11.txt");
FileInputStream fis;
try {
fis = new FileInputStream(file); // 创建字节流
InputStreamReader reader = new InputStreamReader(fis); // 创建字符流
BufferedReader br = new BufferedReader(reader); // 创建缓冲区
String line = br.readLine(); // 读一行
while (line != null) {
System.out.println(line);
line = br.readLine();
br.close();
reader.close();
fis.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
package iotest;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class BufferedWriteDemo {
public static void main(String[] args) {
File file = new File("d://11.txt");
try {
FileOutputStream fis = new FileOutputStream(file);
OutputStreamWriter write = new OutputStreamWriter(fis);
BufferedWriter bw = new BufferedWriter(write);
bw.write("黑泥卡,你好!!!!");
bw.flush();
bw.close();
write.close();
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BufferedReader, BufferedWriter
最新推荐文章于 2024-01-15 10:53:07 发布