aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Default file creation in Eclipse Europa Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Default file creation in Eclipse Europa" Watch "Default file creation in Eclipse Europa" New topic
Author

Default file creation in Eclipse Europa

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

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.

JBoss In Action
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
A good practice it not to rely on the current working directory. Always specify the full path to the file.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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
 
jQuery in Action, 2nd edition
 
subject: Default file creation in Eclipse Europa