1. 程式人生 > >讀取文件內容

讀取文件內容

clas import exceptio ati adf java readfile con app

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(); } }

讀取文件內容