`

读文件时的中文问题的解决

    博客分类:
  • java
阅读更多
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();
	}
	

 参考:http://www.lihuasoft.net/article/show.php?id=580

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics