Reputation: 15
Propably it's simple error but I'm stuck. I keep a .dat file with a text I want to read in the program in the same package as main and base class, and I've got a FileNotFoundException. I tried to change the file on .txt, getting the URI syntax, but that didn't help. Where's the point?
The main class:
package syseks;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
public class main {
public static syseks.base ba;
public main(syseks.base ba){
ba = this.ba;
}
public static void main(String[] args) throws FileNotFoundException {
// TODO code application logic here
ba = new base();
String[] py = ba.loadData('p');
System.out.print(py);
}
}
And the loadData method from base class:
public String[] loadData(char param) throws FileNotFoundException{
List<String> strlist = new ArrayList<String>();
if(param == 'p'){
Scanner sc = new Scanner(new File("py.dat")); //HERE'S THE CRASH
while(sc.hasNextLine()){
strlist.add(sc.nextLine());
}
}
else{
Scanner sc = new Scanner(new File("wy.dat"));
while(sc.hasNextLine()){
strlist.add(sc.nextLine());
}
}
String[] da = strlist.toArray(new String[0]);
return da;
}
Upvotes: 0
Views: 715
Reputation: 362
Display the current directory using System.getProperty("user.dir")
. Make sure it's the directory in which you've saved the .dat file.
Upvotes: 0
Reputation: 1491
Supply an absolute path to the File
constructor argument. Something like:
Scanner sc = new Scanner(new File("/home/foo/proj/myapp/src/syseks/py.dat"));
Upvotes: 1