File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Read files under WEB-INF directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Read files under WEB-INF directory" Watch "Read files under WEB-INF directory" New topic

Read files under WEB-INF directory

Yuvi Gupta

Joined: Apr 25, 2013
Posts: 20

Hi Guys,
I want to get List of all files name(jsp etc) which is under WEB-INF directory. i tried lot but i couldn't do that. Any one can please post the code.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Welcome to the Ranch.

What have you tried? Please post your code. At CodeRanch, you don't get the code handed to you, you get lots of help with your code.

[Asking smart questions] [About Bear] [Books by Bear]
Yuvi Gupta

Joined: Apr 25, 2013
Posts: 20

Hi Bear Bibeault ,
I have solved my problem by the following statement. Thanks
String [] f=new File(getServletContext().getRealPath("WEB-INF")).list();

Ivan Jozsef Balazs

Joined: May 22, 2012
Posts: 970
getResourceAsStream might be a better choice - as getRealPath returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).

How to load a resource from WEB-INF directory of a web archive - Stack Overflow
I agree. Here's the link:
subject: Read files under WEB-INF directory
It's not a secret anymore!