集册 Java实例教程 通过BufferedReader获取流

通过BufferedReader获取流

欢马劈雪     最近更新时间:2020-01-02 10:19:05

497
通过BufferedReader获取流

//package com.nowjava;

import java.io.BufferedReader;


import java.io.ByteArrayInputStream;
/** from 
N  o w  J a v a . c o m**/

import java.io.File;


import java.io.FileReader;


import java.io.IOException;

import java.io.InputStream;


public class Main {

    public static void main(String[] argv) {

        String file = "Main.java";

        System.out.println(getStream(file));

    }


    public static InputStream getStream(String file) {

        File f = new File(file);

        String total = "";/** from nowjava.com - 时  代  Java**/

        try {

            BufferedReader r = new BufferedReader(new FileReader(f));

            String s = r.readLine();

            while (s != null) {

                total += s + "\n";

                s = r.readLine();

            }

            r.close();

        } 
展开阅读全文