读取文件内容

package bianchengti;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/*
 * 读取文件
 */
public class ReadFile {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        InputStream in =new FileInputStream("e:/a.txt");
        
        InputStreamReader isr =new InputStreamReader(in,"GBK");
        
        BufferedReader br =new BufferedReader(isr);
        
        StringBuffer sb =new StringBuffer();
        
        String str =null;
        
        while((str = br.readLine())!= null) {
            sb.append(str);
        }
        
        System.out.println("content:"+sb);
        
        br.close();
    }

}

 

posted @ 2017-09-28 23:10  刘镇平Jasper  阅读(158)  评论(0编辑  收藏  举报