当前位置:网站首页>IO buffered stream case
IO buffered stream case
2022-06-22 11:40:00 【ITzhongzi】
Core code
package ioDemo;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class BufferStreamDemo {
public static void main(String[] args) {
// byteWrite();
// byteReader();
// charReader();
charWrite();
}
private static void byteWrite() {
try {
File file = new File("C:\\Users\\lihw\\Desktop\\test\\123.txt");
OutputStream os = new FileOutputStream(file);
// Construct byte buffer stream
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(" Ha ha ha ha , This guy buffer".getBytes(StandardCharsets.UTF_8));
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void byteReader() {
try {
InputStream is = new FileInputStream("C:\\Users\\lihw\\Desktop\\test\\123.txt");
BufferedInputStream bis = new BufferedInputStream(is);
byte[] bytes = new byte[1024];
int len = -1;
while ((len = bis.read(bytes)) != -1) {
System.out.println(new String(bytes, 0, len));
}
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void charWrite() {
File file = new File("C:\\Users\\lihw\\Desktop\\test\\123.txt");
try (Writer writer = new FileWriter(file); BufferedWriter bw = new BufferedWriter(writer)){
writer.write(" Ha ha ha , This is the test de BufferedWriter The function of ");
} catch (Exception e) {
e.printStackTrace();
}
}
private static void charReader() {
File file = new File("C:\\Users\\lihw\\Desktop\\test\\123.txt");
try (Reader reader = new FileReader(file); BufferedReader br = new BufferedReader(reader);){
char[] chars = new char[1024];
int len = -1;
while ((len = br.read(chars)) != -1) {
System.out.println(new String(chars, 0, len));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
边栏推荐
- jg_ Using easyexcel to read Excel_ twenty million two hundred and twenty thousand six hundred and nineteen
- Go microservice (I) - getting started with RPC
- 牛客挑战赛53C
- Arm load storage instruction
- Realization of simple particle effect in canvas
- Wechat applet project example - image processing gadget (self-made low configuration version of Meitu XiuXiu)
- Web Configuration of Visual Studio Code
- In a word, several common methods of uploading Trojan horse
- 1.11 haas506 2.0开发教程-driver-RTC(仅支持2.2以上版本)
- 两两交换链表中的节点[单向链表不断链原则]
猜你喜欢

Intensive reading: generative adversarial imitation learning

庖丁解牛,这八个MySQL经典错误,你遇到几个?

1.11 haas506 2.0开发教程-driver-RTC(仅支持2.2以上版本)

Development technology of NFT trading platform digital collection system

Interpretation of MAML (model agnostic meta learning)

微信小程序项目实例——图片处理小工具(自制低配版美图秀秀)

“不敢去怀疑代码,又不得不怀疑代码”记一次网络请求超时分析

The software used is PHP MySQL database

牛客挑战赛55E题解

Typical life cycle model of information system project
随机推荐
R language performs two sample t-test on the specified covariates based on the with function, and the t.test function performs Welch two sample t-test analysis and two independent sample t-test on the
R语言使用自定义函数编写深度学习阶跃step激活函数、并可视化阶跃step激活函数
Electron adding SQLite database
lyndon分解学习笔记
How much memory does a TCP connection occupy?
Getting to know elastricearch
R language uses GLM function to build Poisson log linear regression model, processes three-dimensional contingency table data to build saturation model, and uses summary function to obtain model summa
从原型链到继承,图解来龙去脉,推荐收藏
Daily question 5-1636 Sort arrays in ascending order by frequency
Arm load storage instruction
R语言dplyr包mutate函数将dataframe中的两个数值变量相除创建新的数据列(Create a new variable)
The software used is PHP MySQL database
Development technology of NFT trading platform digital collection system
AGCO AI frontier promotion (6.22)
【软工】 软件体系结构
CF736 D2
What is the image used to parse the Tso of the DN binlog? It seems that there is no direct use of mysqlbinlog?
Realization of simple particle effect in canvas
Electron ajoute une base de données SQLite
牛客挑战赛57C题解