This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File loading and paths when running in an IDE, and outside an IDE.

 
Nick Wiggill
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all. My first post here although I first came upon your friendly forums many moons ago.

I'm an experienced developer, but not with Java. And there is something that has really been eating my brain of late that I feel I need to come to terms with. And that is file paths in Java.

I have some questions.


1) Reading and writing files: What is my best option, Files, Streams, <name your own method here>, and why? So far I'm leaning towards streams because they seem more flexible in a sense, but maybe that also makes life a little more difficult.

2) I want to be sure that my application will run happily both in Eclipse, and outside Eclipse as a standalone jar, without file pathing issues. What process should I follow to ensure this is the case?

3) I have also considered deploying as a web-based applet or possibly JNLP, and I'd be really interested to also hear what these entail in terms of getting paths correct; and if there is one good way of designing my applications pathing and loading to deal with any of the above scenarios, so future apps can be more flexible.


I guess that's the gist of it, I might have more Q's as they come to me.

Looking forward to your replies.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Wiggill wrote:2) I want to be sure that my application will run happily both in Eclipse, and outside Eclipse as a standalone jar, without file pathing issues. What process should I follow to ensure this is the case?

If you don't need to write to these files you should use resources; check out Class.getResource and Class.getResouceAsStream, and their cousins in ClassLoader.
 
Campbell Ritchie
Sheriff
Posts: 48436
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Nick Wiggill
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, both
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic