当前位置:网站首页>IO之Reader案例
IO之Reader案例
2022-06-22 11:11:00 【ITzhongzi】
核心代码
package ioDemo;
import java.io.*;
import java.nio.charset.Charset;
/** * outputStreamWriter 可以将输出的字节流转换成字符流输出 * InputStreamReader 可以将输入的字节流转换成字符流 */
public class ChangeStreamDemo {
public static void main(String[] args) {
try {
// InputStream is = new FileInputStream("C:\\Users\\lihw\\Desktop\\test\\123.txt");
// read(is);
OutputStream os = new FileOutputStream("C:\\Users\\lihw\\Desktop\\test\\123.txt");
writeDemo(os);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void read(InputStream in) {
try {
Reader reader = new InputStreamReader(in, Charset.defaultCharset());
char[] chars = new char[1024];
int len = -1;
while ((len = reader.read(chars)) != -1) {
System.out.println(new String(chars, 0, len));
}
System.out.println("读取完毕");
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
}
public static void writeDemo(OutputStream out) {
try {
Writer writer = new OutputStreamWriter(out);
writer.write("开开心心来玩耍");
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
边栏推荐
- 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
- Go microservice (I) - getting started with RPC
- MAML (Model-Agnostic Meta-Learning) 解读
- 牛客挑战赛53C
- R language uses user-defined functions to write step activation functions for deep learning and visualize step activation functions
- PHP website, how to achieve the function of batch printing express orders?
- 机器人强化学习——Sim-to-Real Robot Learning from Pixels with Progressive Nets (2017)
- 奋斗吧,程序员——第三十七章.雄关漫道真如铁,而今迈步从头越
- R language uses read Table load the data set (CSV data) of conditional logistic regression analysis, and use the unique function to view the number of groups of paired data
- 奋斗吧,程序员——第四十二章 会挽雕弓如满月,西北望,射天狼
猜你喜欢
随机推荐
“不敢去怀疑代码,又不得不怀疑代码”记一次网络请求超时分析
Go microservice (I) - getting started with RPC
IDE 的主题应该用亮色还是暗色?终极答案来了!
Basic principles of the Internet
2022年度敏捷教练行业现状报告(2022 State of Agile Coaching Report)
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and uses visual analysis to test the balance of all covariates i
R language uses user-defined functions to write step activation functions for deep learning and visualize step activation functions
Solve the problem that the chrome icon of Google browser in win7 taskbar is missing and abnormally blank
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 language uses user-defined functions to write in-depth learning parametric relu activation functions and visualize parametric relu activation functions
Arm load storage instruction
2022 the latest software testing classic summarized by major manufacturers. After reading it, I'm not afraid I won't get an offer
2022 state of agile coaching Report
puzzle(019)平面正推问题
初识ElastricSearch
"Dare not doubt the code, but have to doubt the code" a network request timeout analysis
[understanding of opportunity -28]: Guiguzi - Internal Defense chapter - protect yourself and persuade your boss
GEE——Global Flood Database v1 (2000-2018)
Three transition schemes from IPv4 to IPv6
Ones attends the first "Lean Software Engineering Conference" to share performance improvement practices









