我正在尝试将文件复制到另一个文件。该文件使用编码标准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();
}
答案 0 :(得分:0)
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(new File("path of the output file")),
"UTF-8"));
或者在java 7中使用Files.copy
。