I have created a class that has the features of reading and writing to a file even parsing what is in the file. But when I run my test, I am not able to read the file. This is the snippet of what I have, if it is not enough I can post the rest of what I have to help.
this is what my main looks like:
public static void main(String args[]) throws IOException {
String fileLocation = File.separator + "Users" + File.separator + "Desktop" + File.separator + "test.txt";
File file = new File(fileLocation);
DataStorage data = new DataStorage(fileLocation);
data.read();
}
this is what my read method looks like:
public File file;
public DataStorage(String filePath) {
setFile(filePath);
}
public Data read() throws IOException {
Data db = new Data();
Scanner scan = new Scanner(file);
Person person;
//check if file has data print selected data
while(scan.hasNextLine()) {
person = parsePerson(scan.nextLine());
db.add(person);
}
if(scan != null) {
// close() may throw IOException if fails;
scan.close();
}
return db;
}