This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.