• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default file creation in Eclipse Europa

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I'm building an web app in Eclipse Europa, In one of Java class, i created a text file "job.txt" as


And in other class I'm able to read it as


But my problem is, I can not figure out where this file is actually get stored ?

Where default files gets stored though Eclipse, I searched Tomcat directories and workspace and installation files of eclipse
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short answer: it goes into the "current working directory".

Long answer: Finding out where the current working directory is located is sometimes not that easy. It could be the bin directory of Eclipse or of Tomcat. If you launched Eclipse via a new item or shortcut, the current working directory could be specified in that shortcut. As an example, if you opened a terminal window, cd'ed to the Tomcat bin directory, and ran the startup script, the file would appear in the Tomcat bin directory.

One way to cheat: do:

File f = new File("job.txt");

and then pass 'f' tp the FileOutputStream. You should be ablte to use f.getAbsolutePath() to get the full path name - send it to the log file or display it. Then you will know the directory.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good practice it not to rely on the current working directory. Always specify the full path to the file.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Johnson wrote:Short answer: it goes into the "current working directory".



You Rocks !!
And thanks Bauke, for suggesting " Use best and avoid future trouble"
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A good practice it not to rely on the current working directory.



Absolutely true! My post implied this but never came right out and said it.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whatever you do, DON'T write the file to the webapp (WAR) itself! I've seen some serious problems with code that did that.

Normally, when I need a webapp to store files in the server's filesystem, I make the destination directory a JNDI definition. That way I can specify its default in the web.xml file and override it if needed (for example, for testing).

As people have already said, the destination directory should always be an absolute path. That way you won't get unpleasant surprises.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Normally, when I need a webapp to store files in the server's filesystem, I make the destination directory a JNDI definition. That way I can specify its default in the web.xml file and override it if needed (for example, for testing).


Excellent

I haven't used JNDI beyond the Database connectivity.. and now this is something new lesson for me. Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic