我已成功将图像上传到 c:/images 如何上传到我的根文件夹中?
String fileName = getFileName(filePart);
FileOutputStream os = new FileOutputStream("C:/images" + fileName);
os.write(b);
最佳答案
您可以使用ServletContext.getRealPath(relativePath)
来获取文件的真实路径。
String relativePath="/images/" + fileName;
String realPath=getServletContext().getRealPath(relativePath);
FileOutputStream stream=new FileOutputStream(realPath);
关于java - 如何上传根文件夹中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11897456/