Help With Netbeans dat files

john1992

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

 

randomizer

Distinguished
Moderator
Jul 24, 2006
880
0
19,260
62
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.
 

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
0
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
Moderator
Jul 24, 2006
880
0
19,260
62
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.
 
Thread starter Similar threads Forum Replies Date
B Apps General Discussion 2
E Apps General Discussion 0
A Apps General Discussion 2
R Apps General Discussion 11
J Apps General Discussion 1
S Apps General Discussion 1
P Apps General Discussion 1
T Apps General Discussion 10
M Apps General Discussion 5
D Apps General Discussion 6
E Apps General Discussion 3
M Apps General Discussion 5
T Apps General Discussion 2
S Apps General Discussion 6
A Apps General Discussion 3
Heiski Apps General Discussion 1
A Apps General Discussion 4
jgonzo Apps General Discussion 8
H Apps General Discussion 1
A Apps General Discussion 1

ASK THE COMMUNITY