Forums Register Login

creating file relative to root of web application in windows OS

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Hi
I got servletcontext path from request.getSession().getServletContext().getRealPath("/") . appended it to directory path given by back and it works fine.
+Pie Number of slices to send: Send
 

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?
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2155 times.
Similar Threads
FILE PROBLEM
Shared Drive access from WebSphere
deploy application in server
Java .IO
Apache commons file upload does not work for me.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:31:39.