Skip to main content



      Home
Home » Newcomers » Newcomers » Eclipse file path problem
Eclipse file path problem [message #118271] Thu, 17 November 2005 06:18 Go to next message
Eclipse UserFriend
Originally posted by: muppet_tizer.hotmail.com

My class uses a relative path to open a file MyFile.txt
e.g. the package is com.test.myprogram.MyClass

The relative path in my code is ../../../ so it should go back three
folders from the folder com where MyFile.txt is located.

However the problem is that when I run it inside Eclipse it uses the
project file as the location to go back from.

Hope you understand.
Re: Eclipse file path problem [message #118478 is a reply to message #118271] Fri, 18 November 2005 17:09 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse3.rizzoweb.com

MT wrote:
> My class uses a relative path to open a file MyFile.txt
> e.g. the package is com.test.myprogram.MyClass
>
> The relative path in my code is ../../../ so it should go back three
> folders from the folder com where MyFile.txt is located.
>
> However the problem is that when I run it inside Eclipse it uses the
> project file as the location to go back from.

Generally it is good practice to use Class.getResource() or
getResourceAsStream() to read files. That way you specify the file
location as relative to the class not a fixed position on the file system.
If you do that you'll have less trouble making it work in different
environments.

HTH,
Eric
Previous Topic:Multiple Perspectives?
Next Topic:.classpath problem?
Goto Forum:
  


Current Time: Wed May 28 19:26:24 EDT 2025

Powered by FUDForum. Page generated in 0.10579 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top