Reputation: 199
So here is my constructor for a library class
package OOD_PROJECT_PACKAGE;
import java.awt.Event;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import javax.swing.DefaultListModel;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class Library {
private ArrayList<Book> books = new ArrayList<Book>();
private ArrayList<Member> members = new ArrayList<Member>();
private DefaultListModel mod1;
//private DefaultListModel mod2;
private int nextValidId;
public Library(){
try {
String fileName = "id.txt";
Scanner in = new Scanner(new File(fileName));
nextValidId = in.nextInt();
}
catch (FileNotFoundException e){
JOptionPane.showMessageDialog(null, "File not found");
//this wont happen,file will always be there
}}
And i have a id.txt file in the source files.Yet it does not seem to be finding it and an expection occurs.I presume this has something to do with the fact the .txt does not have any form of package OOD_PROJECT_PACKAGE,so my library class cant see it.
How do i fix this?Thanks
Upvotes: 1
Views: 3970
Reputation: 348
If your project folder is H:/netbeans/OOD_PROJECT/ then you should put the id.txt in that folder, not H:/netbeans/OOD_PROJECT/src/.
In case you're planning on using the absolute path then the string should be: "H://netbeans//OOD_PROJECT//" or "H:\netbeans\OOD_PROJECT\" (I normally don't pay attention to whether I used \ or / but both seems to work for me).
Upvotes: 4