• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 41071
848
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: 41071
848
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.
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic