码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA_BufferedIO

时间:2015-05-10 06:14:33      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

技术分享

 

 1 import java.io.*;
 2 public class TestBufferStream1 {
 3   public static void main(String[] args) {
 4     try {
 5       FileInputStream fis = 
 6               new FileInputStream("d:\\share\\java\\HelloWorld.java");
 7       BufferedInputStream bis = 
 8               new BufferedInputStream(fis);
 9       int c = 0;
10       System.out.println(bis.read());
11       System.out.println(bis.read());
12       bis.mark(100);
13       for(int i=0;i<=10 && (c=bis.read())!=-1;i++){
14         System.out.print((char)c+" ");
15       }
16       System.out.println(); 
17       bis.reset();
18       for(int i=0;i<=10 && (c=bis.read())!=-1;i++){
19         System.out.print((char)c+" ");
20       }
21       bis.close();
22     } catch (IOException e) {e.printStackTrace();}
23   }
24 }

 

 1 import java.io.*;
 2 public class TestBufferStream2 {
 3   public static void main(String[] args) {
 4     try {
 5       BufferedWriter bw = new BufferedWriter(new FileWriter("d:\\share\\java\\dat2.txt"));
 6       BufferedReader br = new BufferedReader(
 7              new FileReader("d:\\share\\java\\dat2.txt"));
 8       String s = null;
 9       for(int i=1;i<=100;i++){
10         s = String.valueOf(Math.random());
11         bw.write(s);
12         bw.newLine();
13       }
14       bw.flush();
15       while((s=br.readLine())!=null){
16         System.out.println(s);
17       }
18       bw.close(); 
19       br.close();
20     } catch (IOException e) { e.printStackTrace();}
21   }
22 }

 

JAVA_BufferedIO

标签:

原文地址:http://www.cnblogs.com/roger-h/p/4491571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!