[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: Problem with finding a text file in Eclipse workspace

Dave Wegener wrote:
Stefan Zugal wrote:
Anyway, if you want to take advantage of the Eclipse workspace, you will need the org.eclipse.core.resources plugin:

ResourcesPlugin.getWorkspace()

will return the workspace. Eclipse help should give you more information about how to use the workspace.


If you want to access files of your plugin, you may use:
Bundle#getResource(String name)

HTH,
Stefan

This is the procedure to follow if you are writing an Eclipse plugin. To me, it sounds more like you are writing a Java application. In this case, you should look into the Class.getResource() and Class.getResourceAsStream() methods. These will search for the resource on your classpath. My guess is that something along the lines of: this.getClass().getResourceAsStream("/temp.txt") should work. Read the Javadoc for both methods and pay attention to the discussion about leading '/' characters for pathing purposes.

And to get the text file to be on the classpath by default, store it in the source directory along with your Java code. Eclipse automatically copies non-Java files from the source directories to the build output, so they are on the runtime classpath by default.
Alternatively, you can create an additional source directory just for storing non-Java resources. That is actually the "clean" way to do it.


Hope this helps,
	Eric