public void copy(String sourcePath){
int b;
try{
String filename=this.getSourceFileName(sourcePath);
copyFile=new File(copyPath+fileFullName);
FileInputStream in= new FileInputStream(sourcePath);
FileOutputStream out=new FileOutputStream(copyFile);
while((b=in.read())!=-1) //你这里读了一次(奇数字符),这个没被写入
{
out.write(in.read()); //这里又读了一次文件,只写了这一次读的内容
}
}
catch(Exception e){
System.out.println(e.toString());
}
}
给你改了一下,测试过了,没问题。
public void copy(String sourcePath){
int b = 0;
byte[] data = new byte[500]; try{
String filename=this.getSourceFileName(sourcePath);
copyFile=new File(copyPath+fileFullName); FileInputStream in= new FileInputStream(sourcePath);
DataInputStream is = new DataInputStream(in); FileOutputStream out=new FileOutputStream(copyFile);
DataOutputStream os = new DataOutputStream(out); while((b=is.read(data))!= -1)
{
out.write(data);
}
}
catch(Exception e){
System.out.println(e.toString());
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货