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