日期:2014-05-18  浏览次数:20690 次

上传文件的路径问题
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( "/ ");