No such file or directory: 'h1.txt' code example

Example 1: No such file or directory: 'h1.txt'

{
String lastName, firstName, status, gender;
File list;
File outFile;
int i = 0;
list = new File("/⁨Users/3020418⁩/⁨Desktop⁩/List.txt");
outFile = new File("ShoppingList.txt");
FileOutputStream outFileStream = new FileOutputStream(outFile);
PrintWriter outStream = new PrintWriter(outFileStream);
Scanner scanner = new Scanner(list);
while(scanner.hasNext()){
gender = scanner.next();
firstName = scanner.next();
lastName = scanner.next();
status = scanner.next();
if(status.equals("Bad")){

outStream.println(lastName + ", " + firstName + " Coal");
numLumps++;
}
else if(gender.equals("F")){
outStream.println(lastName + ", " + firstName + " Pony");
numPonies++;
}
else{
outStream.println(lastName + ", " + firstName + " Bicycle");
numBicycles++;
}
}
outStream.println("\nLumps of Coal: " + numLumps);
outStream.println("Ponies: " + numPonies);
outStream.println("Bicycles: " + numBicycles);
outStream.close();
scanner.close();
}

Example 2: FileNotFoundException: properties/fortunes.txt (No such file or directory)

Project_Root
    src
    word.txt

Tags:

Java Example