在以下代码段中:
ServletContext context = request.getServletContext();
String path = context.getRealPath("/");
Run Code Online (Sandbox Code Playgroud)
是什么/在方法getRealPath()代表什么呢?我应该什么时候使用它?
我想创建一个xml文件并存储在我的Spring Mvc Web应用程序的文件夹中.
我可以用我的应用程序的根目录 request.getContextPath()
但
我如何获得应用程序的相对路径,以便它可以在应用程序文件夹的位置独立地在任何机器上工作?
喜欢 C:/folder/folder/MYAPPLICATIONROOTFOLDER
我有个问题。我想转换BufferedImage为 MultipartFile。首先,在我的 UI 上发送base64到服务器,在我的服务器上,我转换为BufferedImage之后我想要将 BufferedImage 转换为 MultipartFile 并保存在本地存储上。这是我的方法:
@PostMapping("/saveCategory")
@ResponseStatus(HttpStatus.OK)
public void createCategory(@RequestBody String category ) {
BufferedImage image = null;
OutputStream stream;
byte[] imageByte;
try {
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(category);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
String fileName = fileStorageService.storeFile(image );
Run Code Online (Sandbox Code Playgroud)
我的存储方法:
public String storeFile(MultipartFile file) {
// Normalize file name
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
try {
// Check …Run Code Online (Sandbox Code Playgroud)