java Web 应用程序将图像保存在项目文件夹中
java web appliaction save image on project folder
我正在尝试将图像文件保存到我的项目文件夹中。
图像文件来自数据库。
它是一个 maven 项目和 rest web 服务。
我没有任何 servlet。
这是我的代码,但它保存在 eclipse 文件夹中。
byte[] imgData = null;
Blob img = null;
img = resultset.getBlob("LOGO");
imgData = img.getBytes(1, (int) img.length());
BufferedImage img2 = null;
img2 = ImageIO.read(new ByteArrayInputStream(imgData));
File outputfile = new File("birimler/"+resultset.getString("BASLIK")
+ "Logo.png");
outputfile.mkdirs();
ImageIO.write(img2, "png", outputfile);
System.out.println(outputfile.getAbsolutePath());
输出为:/Users/xxx/Documents/eclipse/Eclipse.app/Contents/MacOS/birimler/imageLogo.png
感谢帮助!
那是因为eclipse的工作目录是他的安装文件夹。
提供完整的绝对路径,或更改 运行 配置的工作目录。
File outputfile = new File("/birimler/"+resultset.getString("BASLIK")
+ "Logo.png");
会在
结束
"/birimler/imageLogo.png"
再添加一个斜杠:
File outputfile = new File("/birimler/"+resultset.getString("BASLIK")
+ "/Logo.png");
会产生:
"/birimler/image/Logo.png"
我正在尝试将图像文件保存到我的项目文件夹中。 图像文件来自数据库。 它是一个 maven 项目和 rest web 服务。 我没有任何 servlet。 这是我的代码,但它保存在 eclipse 文件夹中。
byte[] imgData = null;
Blob img = null;
img = resultset.getBlob("LOGO");
imgData = img.getBytes(1, (int) img.length());
BufferedImage img2 = null;
img2 = ImageIO.read(new ByteArrayInputStream(imgData));
File outputfile = new File("birimler/"+resultset.getString("BASLIK")
+ "Logo.png");
outputfile.mkdirs();
ImageIO.write(img2, "png", outputfile);
System.out.println(outputfile.getAbsolutePath());
输出为:/Users/xxx/Documents/eclipse/Eclipse.app/Contents/MacOS/birimler/imageLogo.png
感谢帮助!
那是因为eclipse的工作目录是他的安装文件夹。 提供完整的绝对路径,或更改 运行 配置的工作目录。
File outputfile = new File("/birimler/"+resultset.getString("BASLIK")
+ "Logo.png");
会在
结束"/birimler/imageLogo.png"
再添加一个斜杠:
File outputfile = new File("/birimler/"+resultset.getString("BASLIK")
+ "/Logo.png");
会产生:
"/birimler/image/Logo.png"