public static void copyFile(File src,File dest){
try{
FileInputStream in = new FileInputStream(src);
FileOutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length = -1;
while((length = in.read(buffer)) != -1){
out.write(buffer,0,length);
}
out.flush();
out.close();
in.close();
}catch(Exception e){
System.out.println(e);
}
}
上面的是拷贝文件的方法,我的XML文件格式是UTF-8,里面有一堆中文,经过上面的方法拷贝到另一个地方后,里面的中文就变成了乱码,我该如何解决呢?
另:我的XML例子
<?xml version="1.0" encoding="UTF-8"?>
<AA>
<BB id="1" name="中文">
<CC name="中文"/>
</BB>
<BB id="2" name="中文"/>
</AA>
try{
FileInputStream in = new FileInputStream(src);
FileOutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length = -1;
while((length = in.read(buffer)) != -1){
out.write(buffer,0,length);
}
out.flush();
out.close();
in.close();
}catch(Exception e){
System.out.println(e);
}
}
上面的是拷贝文件的方法,我的XML文件格式是UTF-8,里面有一堆中文,经过上面的方法拷贝到另一个地方后,里面的中文就变成了乱码,我该如何解决呢?
另:我的XML例子
<?xml version="1.0" encoding="UTF-8"?>
<AA>
<BB id="1" name="中文">
<CC name="中文"/>
</BB>
<BB id="2" name="中文"/>
</AA>
用"utf-8"编码输入流看看
Windows的话
Runtime.getRuntime.exec("cmd /c copy oldfile newfile");
UNIX的话
Runtime.getRuntime.exec("cp oldfile newfile");
(怎么设置???)
不过看这段代码是没有问题的,奇怪。