当前位置:网站首页>Advanced API (character stream & net for beginners)
Advanced API (character stream & net for beginners)
2022-07-03 07:01:00 【Bugxiu_ fu】
Transformation flow :
FileReader-- Character input stream ( Read )
FileWriter-- Character output stream ( write in )
The basic format :
Read :
A character by character reading
FileReader fr = new FileReader(file);
int n = 0;
while((n=fr.read())!=-1){
System.out.println((char)n); Compared to byte stream Even one by one Can also read Chinese
}
fr.close();
Line by line reading : Our chat is also sent line by line It is not a word by word transmission
File file = new File("f:\\ picture \\6.txt");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String str = null;
while((str = br.readLine())!=null){
System.out.println(str);
}
br.close();
fr.close();
write in
Scanner mys = new Scanner(System.in);
File file = new File("f:\\ picture \\6.txt");
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
while(true){
System.out.println(" Please enter the content you want to save :");
String str = mys.next();
bw.write(str);
bw.flush();// Be sure to remember to flush the buffer
bw.newLine();// A new line
if(str.equals("exit")){
break;
}
}
bw.close();
fw.close();
边栏推荐
- 卡特兰数(Catalan)的应用场景
- Software testing learning - the next day
- Ruoyi interface permission verification
- 10000小时定律不会让你成为编程大师,但至少是个好的起点
- How to specify the execution order for multiple global exception handling classes
- 【code】if (list != null && list.size() > 0)优化,集合判空实现方式
- Troubleshooting of high CPU load but low CPU usage
- Thoughts in Starbucks
- Upgrade CentOS php7.2.24 to php7.3
- DNS forward query:
猜你喜欢
My 2020 summary "don't love the past, indulge in moving forward"
Golang operation redis: write and read hash type data
Daily question brushing record (11)
Software testing assignment - day 1
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
POI excel percentage
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
卡特兰数(Catalan)的应用场景
Mise en place d'un environnement de développement de fonctions personnalisées
Notes on the core knowledge of Domain Driven Design DDD
随机推荐
2022年华东师范大学计科考研复试机试题-详细题解
机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)
CentOS switches and installs mysql5.7 and mysql8.0
C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
MySQL syntax (basic)
[LeetCode]404. Sum of left leaves
萬卷書 - 價值投資者指南 [The Education of a Value Investor]
2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
JMeter test result output
2022-06-23 VGMP-OSPF-域間安全策略-NAT策略(更新中)
Thoughts in Starbucks
Unit test framework + Test Suite
POI excel percentage
如何迁移或复制VMware虚拟机系统
修改MySQL密码
Software testing learning - day one
instanceof
Code management tools
Golang operation redis: write and read hash type data
Golang operation redis: write and read kV data