读书人

上传文件的路径有关问题

发布时间: 2012-01-14 20:02:35 作者: rapoo

上传文件的路径问题
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
CommonFunction cf=new CommonFunction();
bid_picture=cf.getRandom()+ ".gif ";//上传图片的名字
File newFile = new File( "c:/temp/ " +bid_picture);
try
{
fileItem.write(newFile);
} catch (Exception e)
{
e.printStackTrace();
}
}

我现在上传图片只能上传到指定的盘符下,有什么办法能让文件上传到项目的相对路径下呢?

[解决办法]
获取Web项目的全路径
String strDirPath = getServletContext().getRealPath( "/ ");

读书人网 >Java Web开发

热点推荐