• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

how to read a folder outside the context

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My current application setup is this

/usr/AppServer/CDev/Sections.ear/sectionSite/all-listings

I would like to read a folder thats in another location on the same box.


/usr/DiffServer/sectionSite/small-site/sports-news

from my JSP I'm doing
<%
currDir= new File("/usr/DiffServer/sectionSite/small-site/sports-news");
for (File dirItem : currDir.listFiles()) {
out.print("items "+dirItem.getName());
}
%>

Ofcourse I get a null pointer. What am I doing wrong and if its possible how do I get the list of files under /sports-news folder?
 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java code in a JSP?

First step is to move that out of a JSP and into a Java class.

Second, what do you mean "of course"?

Check the path to the file, and check the permissions. There's nothing special about file I/O in a web app -- it follows all the same rules.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can always use any folder on hard drive...if its outside your context, use full path to the folder, i.e. C:\...\...\... and so on.....
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic