tomcat - java jax rs access files on server -
running tomcat 7.0 have file in web-inf folder accessible through browser by:
http://localhost:8080/wsdarwin_1.0.0/hello.txt
how go accessing file , contents in java code ( using relative links, guess ). can access fine using buffered reader , accessing full url such:
url requesturl = new url(path_prefix_two+"/request.txt"); bufferedreader testin = new bufferedreader(new inputstreamreader(requesturl.openstream()));
but isn't there way access 'locally' ? i'm not using maven
for example, accessing file locally permits me this: bufferedreader testin = new bufferedreader(new filereader(new file(path_prefix+"/request.txt"))); path_prefix = "c:/users/username/.../hello.txt";
if change path_prefix "/hello.txt", not access ( file not found error )
not sure if you're looking for, if file deployed in web-inf/classes or in jar in web-inf/lib, can access via thread.currentthread().getcontextclassloader().getresourceasstream(name)
name
if full name of resource (eg: /pkga/pkgb/hello.text
).
this portable solution, there's no need specify absolute path in server's file system.
Comments
Post a Comment