JAVA_BufferedIO

 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 }
时间: 2024-10-05 09:29:56

JAVA_BufferedIO的相关文章