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

java 流 读

时间:2014-10-02 00:48:11      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   java   sp   div   c   

  

package 流;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;

public class 读 {
    
    public static void main(String[] args) {

        BufferedReaderDemo();
    }
    
    
    public static void InputStreamDemo(){
        try {
            InputStream inputStream=new FileInputStream("d://test.txt");
            int ch=0;
            try {
                while((ch=inputStream.read())!=-1)
                {
                    System.out.print((char)ch);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    

    public static void FileReaderDemo(){
        
        FileReader fileReader;
        try {
            fileReader = new FileReader("d://test.txt");
            int ch=0;
            try {
                while((ch=fileReader.read())!=-1)
                {
                    System.out.print((char)ch);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    public static void BufferedReaderDemo(){
        
        try {
            BufferedReader bufferedReader=new BufferedReader(new FileReader("d://test.txt"));
            String data;
            try {
                data = bufferedReader.readLine();
                while(data!=null)
                {
                    System.out.println(data);
                    data=bufferedReader.readLine();
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }



}

 

java 流 读

标签:style   blog   color   io   ar   java   sp   div   c   

原文地址:http://www.cnblogs.com/huangcongcong/p/4003725.html

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