This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default file creation in Eclipse Europa

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18169
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic