---
title: "读文件时的中文问题的解决"
author: "semicolon"
date: "2010-10-11T14:05:11Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-10-11T14:05:11Z"
id: 781349
url: "https://codingbug.iteye.com/blog/781349"
---

```
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](http://www.lihuasoft.net/article/show.php?id=580)