Question

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.

Était-ce utile?

La solution

I did in the following way

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

Autres conseils

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];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top