Hi All,
I am trying to read in a csv file, but I get an error: the file does not exist.
I am not sure that I fully understand how the path and location works.
Cam anyone give my a hand here?
import java.io.*;
public class TryFile {
public static void main(
String[] args) {
//create an object that is a directory
File myDir = new File("C:/eclipse/workspace/blueBug/src");
System.out.println(myDir.getAbsolutePath() + (myDir.isDirectory()?" is ":" is not ") + "a directory");
//create an object that is a file
File myFile = new File(myDir, "forcastFile.csv");
System.out.println(myFile + (myFile.exists()?" does":" does not ") + "exist");
System.out.println("You can" + (myFile.canRead()?" ":"not ") + "read " + myFile);
System.out.println("You can" + (myFile.canWrite()?" ":"not ") + "write " + myFile);
return;
}
}
////////////////////////
Result:
C:\eclipse\workspace\blueBug\src is a directory
C:\eclipse\workspace\blueBug\src\forcastFile.csv doesexist
You can read C:\eclipse\workspace\blueBug\src\forcastFile.csv
You can write C:\eclipse\workspace\blueBug\src\forcastFile.csv
Thanks,