/**
* 寫文本內容到txt文件
* @param fileContent 文件內容
*/
public void writeResultFile(String fileContent) {
//文件存放目錄
String fileDir=ConstDefine
//文件名
String fileName =new SimpleDateFormat(
File resultFile = new File(fileDir
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try {
bufferedReader = new BufferedReader(new StringReader(fileContent));
bufferedWriter = new BufferedWriter(new FileWriter(resultFile));
char buf[] = new char[
//字符緩沖區
int len;
while ((len = bufferedReader
bufferedWriter
}
} catch (IOException e) {
e
} finally {
try {
bufferedWriter
bufferedReader
bufferedWriter
} catch (IOException e) {
e
}
}
}
上面這個方法就是把文本內容寫到txt文件中
修改後的方法如下:(寫文件的時候加上編碼)
/**
* 寫文本內容到txt文件
* @param fileContent 文件內容
*/
public void writeResultFile(String fileContent) {
//文件存放目錄
String fileDir=ConstDefine
//文件名
String fileName =new SimpleDateFormat(
File resultFile = new File(fileDir
BufferedWriter bufferedWriter = null;
try {
bufferedWriter = new BufferedWriter(new OutputStreamWriter (new FileOutputStream(resultFile)
bufferedWriter
} catch (IOException e) {
e
} finally {
try {
bufferedWriter
bufferedWriter
} catch (IOException e) {
e
}
}
}
修改後的方法在window
如果讀取文件的時候遇到亂碼
BufferedReader br = new BufferedReader(new InputStreamReader (new FileInputStream(new File(filePath))
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25687.html