• We hope you have a fantastic holiday season to close out 2025! Thank you all so much for being part of the Tom's Guide community!

Help With Netbeans dat files

john1992

Honorable
Jan 22, 2014
4
0
10,510
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.

 
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
 
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?
 
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.