java如何读取文本内容 并显示出来???格式不能变?代码越简单越好!!

解决方案 »

  1.   


    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;public class ReadUTF8 { /**
     * @param args
     */
    public static void main(String[] args) {
    BufferedReader br = null;

    try {
    br = new BufferedReader(new FileReader("D:\\a.txt"));

    String line = br.readLine();

    while(line != null){

    System.out.println(line);

    line = br.readLine();

    }

    } catch (FileNotFoundException e) {

    e.printStackTrace();

    }catch (IOException e) {

    e.printStackTrace();

    }finally{

    if(br != null)

    try {

    br.close();

    } catch (IOException e) {

    e.printStackTrace();
    }

    }


    }}