if(getImagefile()!=null && getImagefile().length()>0){
String imagefilepathdir = "/images/product/"+ productinfo.getType().getTypeid()+ "/"+ productid+ "/prototype";//构建图片保存的目录
//得到图片保存的真实路径
String imagefilerealpathdir = ServletActionContext.getServletContext().getRealPath(imagefilepathdir);
File imagesavedir = new File(imagefilerealpathdir);
if(!imagesavedir.exists())
imagesavedir.mkdirs(); //如果文件不存在就创建
String imageext = imagefileFileName.substring(imagefileFileName.lastIndexOf('.'));
String imagename = UUID.randomUUID().toString()+imageext;
FileInputStream fileinputstream = new FileInputStream(imagefile);
BufferedInputStream bufferedinputstream = new BufferedInputStream(fileinputstream);
FileOutputStream fileoutputstream = new FileOutputStream(new File(imagefilerealpathdir,imagename));
BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fileoutputstream);
byte[] buf = new byte[1024];
int len=-1;
while((len=bufferedinputstream.read(buf)) != -1){
fileoutputstream.write(buf,0,len);
}
bufferedoutputstream.close();
fileoutputstream.close(); String path = imagefilepathdir+"/"+imagename;
String imagefilepathdir140 = "/images/product/"+ productinfo.getType().getTypeid()+ "/"+ productid+ "/140x";//构建140图片保存的目录
String imagefilerealpathdir140 = ServletActionContext.getServletContext().getRealPath(imagefilepathdir140);
File imagesavedir140 = new File(imagefilerealpathdir140);
if(!imagesavedir140.exists())
imagesavedir140.mkdirs(); //如果文件不存在就创建
File oldfile = new File(imagefilerealpathdir,imagename);
File newfile = new File(imagefilerealpathdir140,imagename);
ImageSizer.resize(oldfile, newfile, 140, imageext);//压缩类
可以正常的上传图片,但是压缩得到的图片是0k的。把oldfile换成“D:\\1.jpg”就可以,我感觉是Oldfile这里得不到图片,但是System.out.println(oldfile); 也可以得到oldfile的长度啊困惑中
String path1 = "e:\\";
String name1 = "1.jpg";
File file3 = new File(path1,name1);
File file2 = new File("e:\\1.jpg");
System.out.println("file3.length="+file3.length());
System.out.println("file2.length="+file2.length());
System.out.println(file2==file3);
上面的打印结果是:
file3.length=112980
file2.length=112980
false谁能告诉我为什么呢?指向的都是同一个文件,打印的文件大小都一样,那为什么2个文件不相等呢?