Sign in with
Sign up | Sign in
Your question

Help With Netbeans dat files

Tags:
  • Apps
  • Scanners
Last response: in Apps General Discussion
Share
August 8, 2014 9:54:01 PM

Caution, extreme noob.

This is netbeans specific, sadly over on their forums they don't answer topics. *sigh*. Anyway, I'm having trouble reading from a dat file, not sure how to set this program up to read from dat files.

For example:
Scanner reader=new Scanner(new File("lab10d.dat");

When I try to run this, the error is "java.io.FileNotFoundException: lab10d.dat". Where do I need to place this dat file, for this program to find it?

Thanks in advance.

More about : netbeans dat files

August 8, 2014 10:07:55 PM

If you just specify the file name it will look in the current working directory. You need to put a relative or absolute path to the file there, or make sure that your file is in the working directory.
m
0
l
August 9, 2014 12:25:59 AM

randomizer said:
If you just specify the file name it will look in the current working directory. You need to put a relative or absolute path to the file there, or make sure that your file is in the working directory.


This is correct.

By default it will look for it in $PWD (Present Working Directory) on POSIX based operating systems or the user.dir property on Windows
m
0
l
Related resources
August 10, 2014 10:33:01 AM

Well, I attempted to do something, this is what I've got now.

String path = "j:\\student files\\student folders\\lab10 - arrays\\lab10d.dat";
path = path.replaceAll("\\", "/");
Scanner reader=new Scanner(new File(path));

I know this is wrong, but I attempted to use an absolute path. Can someone point out where this is wrong, exactly?
m
0
l
August 10, 2014 1:43:13 PM

You only have one backslash after the drive letter (since the first escapes the second but is not part of the string). Don't use backslashes. You replace them with slashes immediately anyway so you might as well start with slashes.
m
0
l
!