当前位置:网站首页>Reader case of IO
Reader case of IO
2022-06-22 11:40:00 【ITzhongzi】
Core code
package ioDemo;
import java.io.*;
import java.nio.charset.Charset;
/** * outputStreamWriter You can convert the output byte stream to character stream output * InputStreamReader Can convert the input byte stream to character stream */
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(" Finished reading ");
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
}
public static void writeDemo(OutputStream out) {
try {
Writer writer = new OutputStreamWriter(out);
writer.write(" Have fun ");
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
边栏推荐
- 一般图最大匹配(带花树)模板
- “不敢去怀疑代码,又不得不怀疑代码”记一次网络请求超时分析
- R language uses user-defined functions to write step activation functions for deep learning and visualize step activation functions
- Understanding of thread deadlock
- 开源代码存在安全隐患:一个项目平均有49个漏洞
- In depth analysis of business model of blind box software development in 2022
- 【软工】 设计模块
- Security risks exist in open source code: an average of 49 vulnerabilities exist in a project
- JG_ fx_ twenty million two hundred and twenty thousand six hundred and twenty
- 奋斗吧,程序员——第四十八章 千金纵买相如赋,脉脉此情谁诉
猜你喜欢

二叉树的前序、中序、后序遍历的两种实现

鉴权之cookie、session、JWT

Basic principles of the Internet

Wechat applet project example - image processing gadget (self-made low configuration version of Meitu XiuXiu)

Interpretation of MAML (model agnostic meta learning)

初识ElastricSearch

Two ways of traversing binary tree: preorder, inorder and postorder

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

Convert the colored liquid image into transparent liquid, and CMU teaches the robot to accurately control how much water is poured into the cup

xlrd. biffh. XLRDError: Excel xlsx file; Not supported solution
随机推荐
Getting to know elastricearch
初识ElastricSearch
TCP connection establishment process (in-depth understanding of the source code and three handshakes)
electron添加SQLite数据库
AGCO AI frontier promotion (6.22)
牛客挑战赛54F题解 & 李超树学习笔记
【云图说】 第244期 三分钟了解容器镜像服务
Basic principles of the Internet
奋斗吧,程序员——第四十七章 所谓伊人,在水一方
R语言dplyr包mutate函数将dataframe中的两个数值变量相除创建新的数据列(Create a new variable)
两两交换链表中的节点[单向链表不断链原则]
Leetcode algorithm refers to offer 24 Reverse linked list
7-1 framework Publishing - publishing framework through NPM
Rtklib postpos carding (taking single point positioning as an example)
Security risks exist in open source code: an average of 49 vulnerabilities exist in a project
Community article | mosn building subset optimization ideas sharing
开源代码存在安全隐患:一个项目平均有49个漏洞
promise升级版async,await来袭,搭配try+catch更香哦
牛客挑战赛53E题解 & 带花树学习笔记
Typical life cycle model of information system project