• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing files in NetBeans

 
Jack Mullaly
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I read data from files which are outside the Netbeans project?

For example I am tring to acces a file from another Project called "Thinking" called "RS.txt" its Absolute path being C:\JavaPrograms\Thinking\RS.txt.

I type this File file = new File("JavaPrograms.Thinking.RS.txt");

I get a File Not Found Exceptions.

Learning this Netbeans is extra work, besides learning Java.
Please help.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34078
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack,
If you call new File() without specifying a path, the IDE uses the current working directory. I don't know where that is for NetBeans. You can find out by writing:
System.out.println(file.getPath());
 
Jack Mullaly
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,
How do you usually specify the path for a file in an IDE?
I tried this: File file = new File("JavaPrograms.Thinking.RS.txt");
Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34078
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack,
I usually use an absolute path, so I would say:
File file = new File("C:\\JavaPrograms\\Thinking\\RS.txt");

The backslashes are escaped because they are special characters in Java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic