码迷,mamicode.com
首页 > 编程语言 > 详细

java 读取文件转换成字符串

时间:2014-10-21 00:41:18      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:io   os   java   sp   文件   on   ad   bs   line   

public String readFromFile(File src) {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(
                    src));
            StringBuilder stringBuilder = new StringBuilder();
            String content;
            while((content = bufferedReader.readLine() )!=null){
                stringBuilder.append(content);
            }
            return stringBuilder.toString();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }

    }

java 读取文件转换成字符串

标签:io   os   java   sp   文件   on   ad   bs   line   

原文地址:http://www.cnblogs.com/rxingyue/p/4039165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!