I am writing a program for my comp sci class, andI keep getting the same error.
Exception in thread "main" java.io.FileNotFoundException: data.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.util.Scanner.<init>(Scanner.java:636)
at Search.main(Search.java:18)
Here is the beginning of my code:
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
public class Search{
public static void main(String[] args)throws IOException{
Scanner inData = new Scanner(new File("data.txt"));
String data=inData.nextLine();
String[] arr = data.split(" ");
while(inData.hasNext()){
String search=inData.nextLine();
int len=search.length();
ArrayList<String> result = new ArrayList<String>();
I have a text file in the same Java Project, so I'm not sure what the problem is and I've tried moving the location of the file around but nothing is working.