java swing打开文件的程序,提示内存溢出

 package newtest;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class Test {

    public static void main(String[] args) {
        final Test test = new Test();
        JFrame f= new JFrame();
        JPanel p = new JPanel();
        p.setLayout(new BorderLayout());
        f.setContentPane(p);
        final JTextArea t = new JTextArea();
        JButton b = new JButton("确定");
        b.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuffer testyy = test.getFileContext("E:\\test.txt");
                t.setText(testyy.toString());
            }
        });
        p.add(t, BorderLayout.CENTER);
        p.add(b, BorderLayout.SOUTH);

        f.setSize(200, 400);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }

    /**
     * 读取文件上下文
     * @param filePath
     *      文件路径
     * @return
     */
    public StringBuffer getFileContext(String filePath) {
        StringBuffer fileContext = new StringBuffer();
        if(filePath != null && !filePath.equals("")) {
            File file = new File(filePath);
            if(file.exists()) {
                if(file.isFile()) {
                    BufferedReader bf = null;
                    InputStreamReader  isr = null;
                    FileInputStream fis = null;
                    try {
                        fis = new FileInputStream(filePath);

                        isr = new InputStreamReader(fis, "GBK");
                        bf = new BufferedReader(isr);
                        String context = null;
                        while ((context=bf.readLine()) != null) {
                            fileContext.append(context);
                            fileContext.append("\n");
                        }
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("获取文件上下文:文件"+filePath+"不支持编码格式");
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("获取文件上下文:文件"+filePath+"未找到");
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("获取文件上下文:文件"+filePath+"读取失败");
                    } finally {
                        try {
                            if(bf != null) {
                                bf.close();
                            }
                            if(isr != null) {
                                isr.close();
                            }
                            if(fis != null) {
                                fis.close();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    System.out.println("文件:"+filePath+"是文件夹无法读取");
                }
            } else {
                System.out.println("文件:"+filePath+"不存在");
            }
        } else {
            System.out.println("获取文件上下文:读取路径为空");
        }
        return fileContext;
    }



}

打开上百兆文件直接提示内存溢出,我用2M小文件测试,用jvisualvm查看发现,内存占用最多的是char[] 和 JTextarea,试了好多方法还是不行,求大神帮帮忙,下图为2M小文件测试的结果:
图片说明
图片说明

http://blog.csdn.net/lkforce/article/details/52094767