复制文件有一种方法出现乱码
2013-07-03 08:34
274 查看
今天随手做了复制文件的代码,发现了一个问题
public void readByPath() throws IOException{
File file=new File("D:/lidahu/lidahu.doc");
File file2=new File("D:/lidahu/lidahu2.doc");
try {
FileInputStream fs=new FileInputStream(file);
FileOutputStream fo = new FileOutputStream(file2);
byte[] name=new byte[(int) file.length()];
if(fs.read(name)!=-1){
fo.write(name);
}
fs.close();
fo.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
上面代码是没有问题的
public void readByPath() throws IOException{
File file=new File("D:/lidahu/lidahu.doc");
File file2=new File("D:/lidahu/lidahu3.doc");
try {
FileReader fs=new FileReader(file);
FileWriter fo = new FileWriter(file2);
char[] name=new char[(int) file.length()+1];
if(fs.read(name)!=-1){
fo.write(name);
}
fs.close();
fo.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
上面的代码就出现问题了,复制的文件打开乱码
目前我还不能解释原因,希望有人能解答下!
public void readByPath() throws IOException{
File file=new File("D:/lidahu/lidahu.doc");
File file2=new File("D:/lidahu/lidahu2.doc");
try {
FileInputStream fs=new FileInputStream(file);
FileOutputStream fo = new FileOutputStream(file2);
byte[] name=new byte[(int) file.length()];
if(fs.read(name)!=-1){
fo.write(name);
}
fs.close();
fo.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
上面代码是没有问题的
public void readByPath() throws IOException{
File file=new File("D:/lidahu/lidahu.doc");
File file2=new File("D:/lidahu/lidahu3.doc");
try {
FileReader fs=new FileReader(file);
FileWriter fo = new FileWriter(file2);
char[] name=new char[(int) file.length()+1];
if(fs.read(name)!=-1){
fo.write(name);
}
fs.close();
fo.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
上面的代码就出现问题了,复制的文件打开乱码
目前我还不能解释原因,希望有人能解答下!
相关文章推荐
- ie引用js文件出现中文乱码的一种解决方法
- Java读取UTF-8格式txt文件第一行出现乱码——问号“?”及解决;Java读带有BOM的UTF-8文件乱码原因及解决方法
- Android读取xxx.properties配置文件中文出现乱码解决方法
- vagrant nginx php开发环境中浏览器访问js文件,文件中出现乱码的解决方法
- ajax出现乱码的一种解决方法
- Java读取UTF-8格式txt文件第一行出现乱码——问号“?”及解决;Java读带有BOM的UTF-8文件乱码原因及解决方法
- XML 文件中出现 & ? ? 这类特殊字符的一种解决方法
- FCKeditor 2.3中文文件上传时出现乱码的解决方法
- FCKeditor 2.3中文文件上传时出现乱码的解决方法
- php-fpm可执行文件出现乱码的解决方法
- tar压缩包解压文件中文名出现乱码解决方法
- js出现中文乱码及VS打开js文件乱码的解决方法
- js出现中文乱码及VS打开js文件乱码的解决方法
- 用fileupload组件上传文件出现乱码解决方法
- eclipse打开文本文件出现乱码解决方法
- android用流把项目里的xml文件复制到sdcard的方法(含乱码问题) ---花了大半天时间
- 关于使用cmd编译java文件出现乱码现象解决方法
- iOS读取txt文件出现中文乱码的解决方法
- Spring读取properties文件出现乱码的解决方法
- 在linux下的使用复制命令cp,不让出现“overwrite”(文件覆盖)提示的方法。