• [Java] IO-02 BufferStream1 / BufferStream2


    import java.io.*;
    
    public class TestBufferStream1 {
        public static void main(String[] args) {
            try {
                FileInputStream fis = new FileInputStream(
                        "d:\share\java\HelloWorld.java");
                BufferedInputStream bis = new BufferedInputStream(fis);
                int c = 0;
                System.out.println(bis.read());
                System.out.println(bis.read());
                bis.mark(100);
                for (int i = 0; i <= 10 && (c = bis.read()) != -1; i++) {
                    System.out.print((char) c + " ");
                }
                System.out.println();
                bis.reset();
                for (int i = 0; i <= 10 && (c = bis.read()) != -1; i++) {
                    System.out.print((char) c + " ");
                }
                bis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
    }
    
    import java.io.*;
    
    public class TestBufferStream2 {
        public static void main(String[] args) {
            try {
                BufferedWriter bw = new BufferedWriter(new FileWriter(
                        "d:\share\java\dat2.txt"));
                BufferedReader br = new BufferedReader(new FileReader(
                        "d:\share\java\dat2.txt"));
                String s = null;
                for (int i = 1; i <= 100; i++) {
                    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();
            }
        }
    }
    


  • 相关阅读:
    linux 中rz sz 文件传输
    linux find 命令
    深度学习的博客
    cifar10数据的转换、代码解释
    gflags的使用实例(转载)
    leveldb使用 (转载)
    (转载+整理)Leveldb安装及例子
    2013-09-25-【随笔】-Roy
    2013-09-22 [随笔]-Roy
    2013-08-12【随笔2】-Roy
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786900.html
Copyright © 2020-2023  润新知