android 读txt文件
周祥·
2013-09-13·
3 次阅读
String content = ""; //文件内容字符串 //打开文件 File file = new File(path); //如果path是传递过来的参数,可以做一个非目录的判断 if (file.isDirectory()) {} else { try { InputStream 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; } instream.close(); } } catch (java.io.FileNotFoundException e) { } catch (IOException e) { } } return content;