Pregunta

I am sorry,may be this is simple question.

I am finding real Path from my web-content folder in the following way.

String directory= request.getRealPath("/JSPFiles");

I got output like this.

 C:\Users\Infratab Bangalore\DesktopSubbuFinal\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ExecutableFileProcess\JSPFiles

I want to find Parent Directory from directory varibale.

C:\Users\Infratab Bangalore\DesktopSubbuFinal\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ExecutableFileProcess

Thanks.

¿Fue útil?

Solución

I did in the following way

   String n=request.getRealPath("/JSPFiles");
   File j=new File(n);
   String jk=j.getParent();
   out.print(jk);

Otros consejos

Alternative way by splitting strings

To get ExecutableFileProcess from that string, or any parent directory for that matter, you can use the split function from the String class, and index the array:

String parentDirectory = directory.split("\\\\")[directory.split("\\\\").length-1];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top