How to read file? java : <p>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.</p>

<p>this is what my main looks like:</p>

<pre><code>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();
}
</code></pre>

<p>this is what my read method looks like:</p>

<pre><code>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;
}
</code></pre>
