Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在我的根文件夹中上载图像?_Java_Jsp_Servlets - Fatal编程技术网

Java 如何在我的根文件夹中上载图像?

Java 如何在我的根文件夹中上载图像?,java,jsp,servlets,Java,Jsp,Servlets,我已成功地将我的图像上载到c:/images 如何在我的根文件夹中上载 String fileName = getFileName(filePart); FileOutputStream os = new FileOutputStream("C:/images" + fileName); os.write(b); 您可以使用ServletContext.getRealPath(relativ

我已成功地将我的图像上载到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);

您可以使用
ServletContext.getRealPath(relativePath)
获取文件的实际路径

String relativePath="/images/" + fileName;
String realPath=getServletContext().getRealPath(relativePath);
FileOutputStream stream=new FileOutputStream(realPath);