Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Scanner File
    primarykey
    data
    text
    <p>I have a scanner to read a .csv file.<br> The file is in the same directory and the .java files, however it can't seem to find the file.<br> What can I do to fix this issue?</p> <pre><code>Scanner scanner = new Scanner(new File("database.csv")); </code></pre> <p>Edit: Sorry forgot to mention that I need to use the Scanner package because in the next line I use a delimiter.</p> <pre><code>Scanner scanner = new Scanner(new File("database.csv")); scanner.useDelimiter(",|\r|\n"); </code></pre> <p>Also I am working in IntelliJIDEA</p> <p>So here is the full code</p> <pre><code>import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.*; public class City { public String name; // The name of the city public String cont; // The continent of the city public int relTime; // Time relative to Hobart (eg. -14 for New York) public boolean dst; // Does the city use DST? public boolean valid; // Does the city exist? Date currDate; City(){}; // Default constructor City(String name, String cont, int relTime) { this.name = name; this.cont = cont; this.relTime = relTime; valid = verify(); if(valid) { currDate = new Date(System.currentTimeMillis() + (3600000 * relTime)); } } City(String name, String cont, int relTime, int dstStartDay, int dstEndDay) { this.name = name; this.cont = cont; this.relTime = relTime; valid = verify(); if(valid) { currDate = new Date(System.currentTimeMillis() + (3600000 * relTime)); // Is DST in effect? if(currDate.after(new Date(currDate.getYear(), 3, dstStartDay, 2, 0)) &amp;&amp; currDate.before(new Date(currDate.getYear(), 11, dstEndDay, 2, 0))) { // It is... so relTime--; } } } private boolean verify() { valid = false; try { Scanner scanner = new Scanner(new File("\\src\\database.csv")); scanner.useDelimiter(",|\r|\n"); while(scanner.hasNext()) { String curr = scanner.next(); String next = new String(); if(scanner.hasNext()) next = scanner.next(); if(curr.contains(cont) &amp;&amp; next.contains(name)) return true; } scanner.close(); } catch(FileNotFoundException e) { e.printStackTrace(); } return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload