I am at the final step of a webpage deployment using jstl and java. It uses a file uploader to upload pictures for users who can then display them on a home page. I am stuck at this step. This is my code:
File uploadDir = new File("/opt/tomcat/webapps/PictureSquirrell/pics/");
for (Part part : request.getParts()) {
fileName = getFileName(part);
part.write(uploadDir + fileName);
}
File file = File.createTempFile(fileName, ".png", uploadDir);
item.write(file);
I want the picture to upload in the pics file on a ubuntu server. however, when I upload the file, it uploads to:
/opt/tomcat/webapps/PictureSquirrell/pics\filename.png
So it gets stored in the project root as opposed to the folder called pics in the project root. Can somebody please help?
Thanks!
Answer
Remove the final forward slash from:
File uploadDir = new File("/opt/tomcat/webapps/PictureSquirrell/pics/");
So it should be
File uploadDir = new File("/opt/tomcat/webapps/PictureSquirrell/pics");