• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating file relative to root of web application in windows OS

 
vani venkat
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have image upload functionality. i get path of directory from back end. my controller(spring) should create directories and save files to the location given by back end.
Problem: when i make directories using mkdirs(), it is making directories in C drive. how do i give path such that these directories are created in my web application root. Here is the path from back end. /upload/images

Code to check whether directory exists and if not , mkdirs.
imageUploadProps.getUploadStorageDirectory() value is /upload/images



I read file documentation. but didnot get how to give path from root of web application with out mentioning drive information.

* For UNIX platforms, the prefix of an absolute pathname is always "/". Relative pathnames have no prefix. The abstract pathname denoting the root directory has the prefix "/" and an empty name sequence.
* For Microsoft Windows platforms, the prefix of a pathname that contains a drive specifier consists of the drive letter followed by ":" and possibly followed by "\" if the pathname is absolute. The prefix of a UNC pathname is "\\"; the hostname and the share name are the first two names in the name sequence. A relative pathname that does not specify a drive has no prefix.

Thanks
 
vani venkat
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I got servletcontext path from request.getSession().getServletContext().getRealPath("/") . appended it to directory path given by back and it works fine.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vani venkat wrote:

Please don't use a String operator for that. imageUploadProps.getUploadStorageDirectory() + DIRECTORY_SEPARATOR + IMAGE already returns a String. Likewise for uploadBaseDirName + DIRECTORY_SEPARATOR + imageUploadProps.getToken().

vani venkat wrote:Hi
I got servletcontext path from request.getSession().getServletContext().getRealPath("/") . appended it to directory path given by back and it works fine.

Why not use the path as a parameter to getRealPath?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!