瀛楃缂撳啿娴丅ufferedWriter鍜孊ufferedWriter

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了瀛楃缂撳啿娴丅ufferedWriter鍜孊ufferedWriter相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/rsh' title='rsh'>rsh   exce   stat   鎹㈣   鏂囦欢   楂樻晥   杈撳叆   鏂瑰紡   cep   

瀛楃缂撳啿娴?/strong>

1銆佸熀鏈敤娉?/strong>

 1 import java.io.BufferedReader;
 2 import java.io.BufferedWriter;
 3 import java.io.FileReader;
 4 import java.io.FileWriter;
 5 import java.io.IOException;
 6 
 7 /**
 8  * BufferedWriter:灏嗘枃鏈啓鍏ュ瓧绗﹁緭鍑烘祦锛岀紦鍐插悇涓瓧绗︼紝浠庤€屾彁渚涘崟涓瓧绗︺€佹暟缁勫拰瀛楃涓茬殑楂樻晥鍐欏叆銆? 9  * BufferedWriter:浠庡瓧绗﹁緭鍏ユ祦涓鍙栨枃鏈紝缂撳啿鍚勪釜瀛楃锛屼粠鑰屽疄鐜板瓧绗︺€佹暟缁勫拰琛岀殑楂樻晥璇诲彇銆?10  * @author Administrator
11  *
12  */
13 public class BufferedStreamDemo {
14     public static void main(String[] args) throws IOException {
15         //鍒涘缓缂撳啿娴佸璞?/span>
16         BufferedWriter bw=new BufferedWriter(new FileWriter("C:\Test\bw.txt"));
17         bw.write("hello");
18         //bw.flush();
19         bw.close();
20         
21         //涓€娆¤鍙栦竴涓瓧绗?22         //鍒涘缓杈撳叆缂撳啿娴佸璞?/span>
23         BufferedReader br=new BufferedReader(new FileReader("C:\Test\bw.txt"));
24         int ch;
25         while((ch=br.read())!=-1) {
26             System.out.print((char)ch);
27         }
28         br.close();
29         System.out.println();
30         //涓€娆¤鍙栦竴涓瓧绗︽暟缁?/span>
31         BufferedReader br2=new BufferedReader(new FileReader("C:\Test\bw.txt"));
32         int len=0;
33         char chs[]=new char[1024];
34         while((len=br2.read(chs))!=-1) {
35             System.out.print(new String(chs,0,len));
36         }
37         br2.close();
38     }
39 }

 2銆佺紦鍐叉祦澶嶅埗鏂囨湰鏂囦欢涓ょ鏂瑰紡

 1 import java.io.BufferedReader;
 2 import java.io.BufferedWriter;
 3 import java.io.FileReader;
 4 import java.io.FileWriter;
 5 import java.io.IOException;
 6 
 7 /**
 8  * 闇€姹傦細鎶婇」鐩矾寰勪笅鐨凚ufferedStreamCopy.java涓殑鍐呭澶嶅埗鍒伴」鐩矾寰勪笅鐨刢opy.java涓? 9  * @author Administrator
10  *
11  */
12 public class BufferedStreamCopy {
13     public static void main(String[] args) throws IOException {
14         BufferedReader br=new BufferedReader(new FileReader("BufferedStreamCopy.java"));
15         BufferedWriter bw=new BufferedWriter(new FileWriter("copy.java"));
16          //绗竴绉嶆柟寮忥紝涓€娆¤鍙栦竴涓瓧绗?17 //        int ch;
18 //        while((ch=br.read())!=-1) {
19 //            bw.write(ch);
20 //        }
21         
22          //绗簩绉嶆柟寮忥紝涓€娆¤鍙栦竴涓瓧绗︽暟缁?/span>
23         int len;
24         char[] chs=new char[1024];
25         while((len=br.read(chs))!=-1) {
26             bw.write(chs,0,len);
27         }
28     
29         br.close();
30         bw.close();
31         
32     }
33 }

 3銆佺紦鍐叉祦鐨勭壒娈婂姛鑳?/span>

BufferedWriter:

銆€銆€銆€銆€void  newLine():鍐欎竴涓崲琛岀锛岃繖涓崲琛岀鐢辩郴缁熷喅瀹?/p>

BufferedReader

銆€銆€銆€銆€String readLine():涓€娆¤鍙栦竴琛屾暟鎹紝浣嗘槸涓嶈鍙栨崲琛岀

 1 import java.io.BufferedReader;
 2 import java.io.BufferedWriter;
 3 import java.io.FileReader;
 4 import java.io.FileWriter;
 5 import java.io.IOException;
 6 
 7 /**
 8  * 闇€姹傦細鎶婇」鐩矾寰勪笅鐨凚ufferedStreamCopy.java涓殑鍐呭澶嶅埗鍒伴」鐩矾寰勪笅鐨刢opy.java涓? 9  * @author Administrator
10  *
11  */
12 public class BufferedStreamCopy {
13     public static void main(String[] args) throws IOException {
14         BufferedReader br=new BufferedReader(new FileReader("copy1.java"));
15         BufferedWriter bw=new BufferedWriter(new FileWriter("copy2.java"));
16         String str;
17         while((str=br.readLine())!=null) {
18             bw.write(str);
19             bw.newLine();
20         }
21         br.close();
22         bw.close();
23         
24         BufferedReader brshow=new BufferedReader(new FileReader("copy2.java"));
25         String str2;
26         while((str2=brshow.readLine())!=null) {
27             System.out.println(str2);
28         }        
29         brshow.close();
30         
31     }
32 }

 

以上是关于瀛楃缂撳啿娴丅ufferedWriter鍜孊ufferedWriter的主要内容,如果未能解决你的问题,请参考以下文章

LNMP鎼缓

缃戠粶缂栫▼ 濂楁帴瀛梥ocket 鍙? 绮樺寘

UOJ266. 銆愭竻鍗庨泦璁?016銆慉lice鍜孊ob鍙堝湪鐜╂父鎴?鍗氬紙璁?01-trie)

灏佽缂撳姩鍔ㄧ敾3

浠庢簮鐮佸垎鏋?MyBatis缂撳瓨 宸ヤ綔鍘熺悊

銆€iOS 缃戠粶璇锋眰缂撳瓨锛歂SURLCache璇﹁В