int poinNum=item.getFieldName().lastIndexOf(".");
String endString=item.getFieldName().substring(poinNum,item.getFieldName().length());
fileNum++;
Date date=new Date();
DateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
String time=format.format(date);
String path="E:\\IWeiBoPhotos/" + time+fileNum+".jpg";
if (imgsPath==null||imgsPath.isEmpty()) {
imgsPath=time+fileNum+"-";
}else {
imgsPath=imgsPath+time+fileNum+endString+"-";
}
paths.add(path);
file = new File("E:\\Project(Elipse)/IWeiBoServer/WebContent/img/" + time+fileNum+endString);
item.write(file);
if (file != null) {
InputStream is;
OutputStream os;
try {
String fName = getServletContext().getRealPath("") + "\\img\\" + time+fileNum+endString;
System.out.println("sssssssssssss---"+fName);
is = new FileInputStream(file.getPath());
os = new FileOutputStream(fName);
byte buffer[] = new byte[1024];
int count = 0;
while ((count = is.read(buffer)) > 0) {
os.write(buffer, 0, count);
}
os.close();
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
代码没有异常,但是存不进去。能够存到硬盘,但是就是存不到webcontent
webcontent 路径可以从servlet中得到吧,把路径打印出来看看
你把fName这个路径打印出来看看是啥