public String getFilterString(final String filePath) {
FileInputStream fis = null;
BufferedReader br = null;
StringBuffer smsFilter = new StringBuffer(); // 定义一个String类型的变量,用来每次读取一行
InputStreamReader isr = null;
try {
if (filePath == null || filePath.length() == 0){
fis = new FileInputStream(DEF_SMS_FILTER_PATH);
} else {
fis = new FileInputStream(filePath);// 创建FileReader对象,用来读取字符流
}
isr = new InputStreamReader (fis,"UTF-8");
br = new BufferedReader(isr); // 缓冲指定文件的输入
while (br.ready()) {
smsFilter.append(br.readLine());// 读取一行
}
} catch (IOException e) {
e.printStackTrace();
} finally{
if (fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (isr != null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (br != null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return smsFilter.toString();
}
读文件时的中文问题的解决
最新推荐文章于 2024-08-12 14:37:51 发布