문제

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.

도움이 되었습니까?

해결책

I did in the following way

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

다른 팁

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top