Java 高效读文本文件

 1 public   static  String getSource(String fileName)  {
 2        
 3        String s="";
 4        File file = new File(fileName);
 5        Reader reader = null;
 6        try {
 7            RandomAccessFile rf=new RandomAccessFile(fileName,"r");
 8            byte  contents[]=new byte[(int)rf.length()];
 9            rf.read(contents, 0, (int)rf.length());
10            s=new String(contents);
11            //s=new String((char[])contents);
12        }
 catch (Exception e) {
13            e.printStackTrace();
14        }

15        return s;
16    }
Homepage: http://www.zoumin.org/
Posted on 2010-05-29 21:38 邹敏 阅读(303) 评论(0)   编辑  收藏 引用

你可能感兴趣的:(Java 高效读文本文件)