I have this very specific need wherein a file is loaded from classpath and the same is used in another module which needs it’s absolute path. What are the possible ways an absolute path of a file loaded via classpath can be deduced ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
ClassLoader.getResource()instead ofClassLoader.getResourceAsStream()to get a URL. It will be, by definition, always absolute.You can then use
openConnection()on the URL to load the content. I’m often using this code: