cool hit counter BufferedIo_Intefrankly

BufferedIo


buffer flow

The buffered streams are "snapped" on top of the corresponding node streams, providing buffering of read and write data, improving the efficiency of reading and writing, and adding some new methods

BufferedReader(Reader in)
BufferedReader(Reader in,int sz)//sz for the custom buffer size
BufferedWriter(Writer out)
BufferedWriter(Writer out,int sz)
BufferedInputStream(InputStream in)
BufferedInputStream(InputStream in,int size)
BufferedOutputStream(OutputStream out)
BufferedOutputStream(OutputStream out,int size)
  • Buffered input streams support the mark and reset methods of their parent class
  • BufferedReader provides ReadLine method for reading a line of string (separated by r or n)
  • BufferedWriter provides newLine for writing a separator
  • For output buffered streams, the written data is first cached in memory, and using the flush method will cause the data in memory to be written immediately

BufferedInputStream

import java.io.*;

public class TestFileInputStream {
    public static void main(String[] args) {
        try {
            FileInputStream fis = 
                    new FileInputStream("D:/test.txt");
            BufferedInputStream bis = 
                    new BufferedInputStream(fis);
            int c = 0;
            System.out.println(bis.read());
            System.out.println(bis.read());
            bis.mark(100);// marker100 six characters, first time out100 Characters to read outwards
            for(int i = 0;i <= 10 && (c = bis.read()) != -1;i++) 
                System.out.println((char)c + " ");
            System.out.println();
            bis.reset();// Back to the marker
            for(int i = 0;i <= 10 && (c = bis.read()) != -1;i++)
                System.out.println((char)c + " ");
            bis.close();
        }catch(IOException e) {
            e.printStackTrace();
        }
    }
}

BufferedReader(Writer)

import java.io.*;

public class TestBuffered{

    public static void main(String[] args) {
        try {
            BufferedWriter bw = 
                    new BufferedWriter(new FileWriter("D:/test4.txt"));
            BufferedReader br = 
                    new BufferedReader(new FileReader("D:/test4.txt"));
            String s = null;
            for(int i = 1;i <= 100;i++) {// write100 row random number
                s = String.valueOf(Math.random());
                bw.write(s);
                bw.newLine();
            }
            bw.flush();
            while((s = br.readLine()) != null) {
                System.out.println(s);
            }
            bw.close();
            br.close();
        }catch(IOException e) {
            e.printStackTrace();
        }
    }
}


Recommended>>
1、SCRATCH Creative Programming Episode 36
2、AlphaZero a generalpurpose chess AI program
3、Cryptocurrencys Largest Fund Galaxydigital to Invest 325 Million in EOSIO
4、The Tesla of Erotic Supplies Banana Smart is Here
5、Call for Industrial Internet Consortium Members

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号