Spring boot 将文件写入spring启动文件夹

Spring boot 将文件写入spring启动文件夹,spring-boot,relative-path,Spring Boot,Relative Path,我的spring boot项目结构如下 src |-主要 |--|-java |--|-资源 静态 |-css |-图像 |-js 现在我想在static/images文件夹中写入一个文件 我试着像这样整理新文件 BufferedOutputStream=new BufferedOutputStream(new FileOutputStream(新文件(“静态/图像”))它将抛出“无此类文件或目录”异常 但是在其他html文件中,我可以通过“js/jsFile.js”获取js,新文件(“静态/图

我的spring boot项目结构如下

src
|-主要
|--|-java
|--|-资源
静态
|-css
|-图像
|-js

现在我想在static/images文件夹中写入一个文件 我试着像这样整理新文件
BufferedOutputStream=new BufferedOutputStream(new FileOutputStream(新文件(“静态/图像”))它将抛出“无此类文件或目录”异常

但是在其他html文件中,我可以通过“js/jsFile.js”

获取js,新文件(“静态/图像”)
是正确的
我使用了
新文件(“/static/images”)
,所以我得到了一个异常

新文件(“static/images”)
是正确的
我使用了
新文件(“/static/images”)
,所以我得到了一个异常

新文件(“static/images”)
是正确的
我使用了
新文件(“/static/images”)
,所以我得到了一个异常

新文件(“static/images”)
是正确的

我使用了
新文件(“/static/images”)
所以我得到了一个异常

我的情况是,使用Spring Boot我必须将映像保存到一个静态访问的目录中

下面的代码工作得很好

byte[] imageByteArray ....
String fileName = "image.png";
String fileLocation = new File("static\\images").getAbsolutePath() + "\\" + fileName;
FileOutputStream fos = new FileOutputStream(fileLocation);
fos.write(imageByteArray);
fos.close();

希望能有所帮助。

我当时的情况是,使用Spring Boot时,我必须将映像保存到一个静态访问的目录中

下面的代码工作得很好

byte[] imageByteArray ....
String fileName = "image.png";
String fileLocation = new File("static\\images").getAbsolutePath() + "\\" + fileName;
FileOutputStream fos = new FileOutputStream(fileLocation);
fos.write(imageByteArray);
fos.close();

希望能有所帮助。

我当时的情况是,使用Spring Boot时,我必须将映像保存到一个静态访问的目录中

下面的代码工作得很好

byte[] imageByteArray ....
String fileName = "image.png";
String fileLocation = new File("static\\images").getAbsolutePath() + "\\" + fileName;
FileOutputStream fos = new FileOutputStream(fileLocation);
fos.write(imageByteArray);
fos.close();

希望能有所帮助。

我当时的情况是,使用Spring Boot时,我必须将映像保存到一个静态访问的目录中

下面的代码工作得很好

byte[] imageByteArray ....
String fileName = "image.png";
String fileLocation = new File("static\\images").getAbsolutePath() + "\\" + fileName;
FileOutputStream fos = new FileOutputStream(fileLocation);
fos.write(imageByteArray);
fos.close();

希望有帮助。

@zhuochenshen是正确的

发生的事情是Eclipse没有显示写文件。所以我看了文件探索。文件正在正确写入

试试看{
Path Path=Path.get(“static/images/”+productDto.getImage().getOriginalFilename());
write(路径,productDto.getImage().getBytes());
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}

@zhuochenshen是正确的

发生的事情是Eclipse没有显示写文件。所以我看了文件探索。文件正在正确写入

试试看{
Path Path=Path.get(“static/images/”+productDto.getImage().getOriginalFilename());
write(路径,productDto.getImage().getBytes());
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}

@zhuochenshen是正确的

发生的事情是Eclipse没有显示写文件。所以我看了文件探索。文件正在正确写入

试试看{
Path Path=Path.get(“static/images/”+productDto.getImage().getOriginalFilename());
write(路径,productDto.getImage().getBytes());
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}

@zhuochenshen是正确的

发生的事情是Eclipse没有显示写文件。所以我看了文件探索。文件正在正确写入

试试看{
Path Path=Path.get(“static/images/”+productDto.getImage().getOriginalFilename());
write(路径,productDto.getImage().getBytes());
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}