Relative path to image folder java spring -


i have problem relative path image folder. want list images folder add urls list , show them in jsp. code this:

file carpetaimagenes = new file("../../../../../webapp/resources/img/maquinas/"+seleccion);     list<string> listaurlimagenes = new arraylist<string>();        /** recorremos el directorio de imagenes de la maquina */     for(file imagen : carpetaimagenes.listfiles()){         string imagefilename = imagen.getname();                 listaurlimagenes.add(imagefilename);       }   

the result of "carpetaimagenes.listfiles()" null. suppose path bad. here can see image of folder tree. class "controlador" folder , images "webbapp/resources/img/maquinas/1" enter image description here

i haeve tried several paths no luck. thank much.

user following method getimagelist , should work

relativefilepath = "img/maquinas/"+seleccion; 

this relative path classpath. assume ../../../../../webapp/resources actual folder everyrthing deployed .

private list getimagelist(string relativefilepath) { list<string> listaurlimagenes = new arraylist<string>(); try {      inputstream in = getresourceasstream(relativefilepath);     bufferedreader br = new bufferedreader(new inputstreamreader(in));     string resource;      while ((resource = br.readline()) != null) {         listaurlimagenes.add(resource);     } } catch (ioexception e) {     // todo auto-generated catch block     e.printstacktrace(); } return listaurlimagenes; } private inputstream getresourceasstream(string resource) { final inputstream in = classloader cl = this.getclass().getclassloader().getresourceasstream(         resource);  return in == null ? getclass().getresourceasstream(resource) : in; } 

and in spring following should work.

classloader cl = this.getclass().getclassloader(); resourcepatternresolver resolver = new pathmatchingresourcepatternresolver(         cl); resource[] resources = resolver.getresources("classpath:/img/maquinas/"+seleccion);// or *.png (resource resource : resources) {   listaurlimagenes.add(resource.getfilename()); } 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -