创建文件流读取文件中的字符串

public  String getUrl(){

File file=new File(mUrlPath);

String content="";

if(file.exists()){

InputStream instream;

try {

instream = new FileInputStream(file);

if (instream != null) 

            {

                InputStreamReader inputreader = new InputStreamReader(instream);

                BufferedReader buffreader = new BufferedReader(inputreader);

                String line;

                //分行读取

                while (( line = buffreader.readLine()) != null) {

                    content += line + "\n";

                }                

                instream.close();

            }

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

             

}

return content;

}

posted @ 2016-07-18 18:08  earthsou  阅读(324)  评论(0编辑  收藏  举报