【发布时间】:2012-12-02 08:47:42
【问题描述】:
我正在尝试将一个文件复制到另一个文件。该文件使用编码标准 UTF8 并且文件也包含特殊字符。程序无法以相同格式复制另一个文件中的特殊字符,该文件被盒子形状干扰 特殊符号。
try
{
BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File("path of the file")),"UTF8") ;
BufferedWriter bw= new BufferedWriter(new OutputStreamReader(new FileOutputStream(new File("path of the output file");
while(br.readLine()!=null)
{
//code here to read and write from a file to another.
}
}
catch(Exception ex
{
ex.printStackTrace();
}
【问题讨论】:
-
Mmmm...您是否也尝试设置编码并为 OutputStreamWriter 设置编码?
-
这里缺少很多右括号。要写一个读行,你必须知道它是什么,你正在失去
br.readLine()返回的东西。