Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.io absolute path restriction  RSS feed

 
Sree Jag
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Can we create/manipulate files using java.io using relative paths?

When i try to create files using relative paths, it says that the file is not found even though the file is present.

Am i doing anything wrong here?

Seshu
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps.
How shall we answer without seing the code?
 
Sree Jag
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Stefan,

sry for not posting the code earlier:

File file = new File ("ApplicationResources.properties");
FileReader read = new FileReader(file);

I'm doing this from c:\eclipse\workspace\myproject

The exception i get is:

java.io.FileNotFoundException: ApplicationResources.properties (The system cannot find the file specified)

And the ApplicationResources.properties file is present in the current working directory given above

How to get around this.

Seshu
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The current directory is going to be the one that was current when you launched Eclipse, not the project directory, as you've shown here.

Eclipse has its own family of calls for locating and opening files in project space, or you can use the Class.getResource() methods, which are what you normally use in a Java app to find a file "near" your application.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!