当前位置:网站首页>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();
边栏推荐
- The dynamic analysis and calculation of expressions are really delicious for flee
- Use the jvisualvm tool ----- tocmat to start JMX monitoring
- Unittest attempt
- Thoughts in Starbucks
- [LeetCode]404. Sum of left leaves
- How to specify the execution order for multiple global exception handling classes
- Summary of remote connection of MySQL
- Modify MySQL password
- RestHighLevelClient获取某个索引的mapping
- Daily question brushing record (11)
猜你喜欢

Daily question brushing record (11)

My 2020 summary "don't love the past, indulge in moving forward"

The dynamic analysis and calculation of expressions are really delicious for flee

Integration test practice (1) theoretical basis

New knowledge! The virtual machine network card causes your DNS resolution to slow down

IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库

10000小时定律不会让你成为编程大师,但至少是个好的起点

In depth analysis of reentrantlock fair lock and unfair lock source code implementation

Use the jvisualvm tool ----- tocmat to start JMX monitoring

Jenkins
随机推荐
爬虫代码基础教学
Strategy mode
The dynamic analysis and calculation of expressions are really delicious for flee
保险公司怎么查高血压?
Software testing assignment - day 3
File links cannot be opened or downloaded in Google browser
dataworks自定義函數開發環境搭建
SQL implementation merges multiple rows of records into one row
10000小時定律不會讓你成為編程大師,但至少是個好的起點
MySQL mistakenly deleted the root account and failed to log in
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
Shim and Polyfill in [concept collection]
Interfaces and related concepts
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
How does the insurance company check hypertension?
MySQL installation
[set theory] partition (partition | partition example | partition and equivalence relationship)
Inno Setup 制作安装包
2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)