文件流读取文件

InputStream is = null;
try {
is = new FileInputStream(textPath);
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
// 读取一行,存储于字符串列表中
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
line = line.trim();
// do something here
}

}catch (FileNotFoundException fnfe){
fnfe.printStackTrace();
}catch (IOException ioe){
ioe.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
is = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}

 

posted on 2017-10-22 21:10  脚踏实地2018  阅读(301)  评论(0)    收藏  举报

导航