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.

 

Pinhedd

Distinguished
Moderator


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
 

john1992

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

randomizer

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