Well, I might have flooded my title a bit but I can't get my java program to find input.txt so I can actually do something with it
This is for homework, I've been trying for the past few hours to get the code to recognize input.txt. I've put "/input.txt" and stuff before just in case, it still didn't work.
0
Output
import java.io.*;
import java.util.Scanner;
public class DataProcessor {
public static void main(String args[]) throws FileNotFoundException {
int[] answers = {0,0,0,0};
File file=new File("input.txt");
Scanner scan=new Scanner(file);
while (scan.hasNextLine()) {
String letter = scan.nextLine();
if (letter.equals("a")) {
answers[0] = answers[0]++;
} else {
if (letter.equals("b")) {
answers[1] = answers[1]++;
} else {
if (letter.equals("c")) {
answers[2] = answers[2]++;
} else {
if (letter.equals("d")) {
answers[3] = answers[3]++;
}
}
}
}
}
System.out.println(answers[0]);
}
}
I expect it to be able to read the file so that I can run the rest of the code, but none of it's working. What am I doing wrong here? It's just been so frustrating. What's supposed to happen is I make an output.txt file but I can't get to that part until I stop it from throwing errors and not reading the input
No longer throwing errors, but is still not reading the file, or something?