Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已成功将我的图像上传到 c:/images 如何上传到我的根文件夹中?
String fileName = getFileName(filePart); FileOutputStream os = new FileOutputStream("C:/images" + fileName); os.write(b);
可以ServletContext.getRealPath(relativePath)用来获取文件的真实路径。
ServletContext.getRealPath(relativePath)
String relativePath="/images/" + fileName; String realPath=getServletContext().getRealPath(relativePath); FileOutputStream stream=new FileOutputStream(realPath);