保存文件的相对路径

时间:2013-04-11 07:23:37

标签: java eclipse struts2 path

我正将我的数据库中的照片复制到路径/WebContent/images/temp/nn.png

中我的网络应用程序中的文件夹

我的目录结构是

friendit/
     WebContent/
               images/
                     temp/
                            nn.png

我将图像从我的Web应用程序的控制器操作类保存到文件夹friendit / webcontent / temp / nn.png但是我得到fileNotFound异常

相对路径有问题! 请帮我解决一下我应该使用的相对路径

1 个答案:

答案 0 :(得分:1)

您无法直接将blob类型从数据库直接保存到硬盘

尝试使用此,

                Blob test=userInfo.getPicture(); //take blob form sql in test variable
                InputStream x=test.getBinaryStream();
                int size=x.available();




                outputStream=new FileOutputStream("./WebContent/images/temp/nn.png");
                byte b[]= new byte[size];
                x.read(b);
                outputStream.write(b);
相关问题