java - Using File API methods on files located in my server -


i've created little app browse file system create , display tree (jtree) . want same files present on server . have apache tomcat server . want :

file dir = new file(new uri("file://localhost:8084/myapp/dir"));    file[] files = dir.listfiles();      (file f : files) {         system.out.println(f.getabsolutepath()); 

this exemple want use java file api .

i getting error when put code in servlet :

11 mai 2011 10:02:15 org.apache.catalina.core.standardwrappervalve invoke "servlet.service()" pour la servlet tests généré une exception java.lang.illegalargumentexception: uri has authority component @ java.io.file.<init>(file.java:385)

i dont know means.

i've tried file dir = new file("dir") ; , file dir = new file("web/dir") , file dir = new file(new uri(http://localhost:8084/myapp/dir));

but dir not found . dont , going mad (hum..sorry) .

when type http://localhost:8084/myapp/dir on web browser content of dir displayed .so dir on http://localhost:8084/myapp/

i really need backup here . in advance .

assuming webapp deployed unpacked war, can use getrealpath() on servletcontext object obtain real filesystem path given webapp path.

so inside servlet:

file dir = new file(getservletcontext().getrealpath("/dir")); 

see javadoc.

note isn't practice, , not work on appserver doesn't unpack wars onto filesystem before running (e.g. google app engine).


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -