• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Accessing files in NetBeans

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 42152
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 42152
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic