gpt4 book ai didi

java - 使用 Java 上传图像无法正确保存在云中

转载 作者:行者123 更新时间:2023-11-30 04:00:32 26 4
gpt4 key购买 nike

我的表单有一个上传按钮,供用户保存文件图像。

ServletContext context = ServletActionContext.getServletContext();

String appPath = context.getRealPath("");
String filePath = appPath+"\\images\\categories";

File fileToCreate = new File(filePath, getMyFileFileName());
FileUtils.copyFile(getMyFile(), fileToCreate);

我需要上传图片并将其放在图像/类别文件夹中以供将来访问。它在我的 localbuild 中运行良好,但是当我通过上传 .war 文件将其部署到云上时,它不再运行。它找不到图像。

访问图片时出现HTML错误如下

type Status report

message /Teapop/images/categories/team.png

description The requested resource (/Teapop/images/categories/team.png) is not available.

我做错了什么?

最佳答案

请尝试使用 File.separator 代替

String filePath = appPath+File.separator+"images"+File.separator+"categories";

请给我一些反馈

希望有帮助。

关于java - 使用 Java 上传图像无法正确保存在云中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22102029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com