大家好 为什么用buffered导出的图片是这样的, 上面的图片是原图, 下面的是我导出的 以下是我全部的代码, 嫌麻烦可以直接看最下面我用=======隔开了,我试过word等其他文件是没有问题的,但是只要是图片就会少内容,是我的代码有问题吗?
package upload;
import java.io.*;
import java.util.*;
public class PhotoUpload {
public void create() throws IOException {
File file = null;
boolean a = true;
do{
System.out.println("请输入上传的图片路径");
String element=new Scanner(System.in).next();
if(!element.endsWith(".jpg")&&!element.endsWith(".bmp")&&!element.endsWith(".png")){
System.out.println("图片格式有误,请重新输入:");
continue;
}
file=new File(element);
if(!file.exists()&&!file.isDirectory()){
System.out.println("输入地址不合法,请重新输入:");
continue;
}
for (String s : new File("src/lib").list()) {
if(s.equals(file.getName())){
System.out.println("图片已经存在,请重新输入");
}else {
a=false;
}
}
}while (a);
try{
if(this.upload(file)){
System.out.println("图片已经保存成功!");
}
}catch (Exception e){
System.out.println("图片保存失败!");
}
}
=====================================================================
//IO代码
private boolean upload(File file) throws IOException {
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("src/lib/"+file.getName()));
int len;
while ((len=bis.read())!=-1){
bos.write(len);
}
bis.close();
bos.close();
return true;
}
}