I am new to Java and am having a difficult time with this particular problem. I created a data.txt file, put the info into it, and placed it in the same package I am working in. When I try to run the code, I get a "System cannot find the file specified" error. I can't for the life of me figure out what I am doing wrong. The ultimate goal is to have the information read from the data file, tokenized, and then printed out using the format I have in a separate control file. Any assistance would be greatly appreciated.
package cs520.hw3.part2;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Test {
public static void main(String[] args)
{
String inputFileName = "data.txt";
FileReader fileReader = null;
try
{
fileReader = new FileReader(inputFileName);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(fileReader);
String input;
try {
input = reader.readLine();
while (input != null)
{
processInputData(input);
input = reader.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void processInputData(String data)
{
StringTokenizer st = new StringTokenizer(data, ",");
String senName = st.nextToken();
String senParty = st.nextToken();
String senState = st.nextToken();
String senYears = st.nextToken();
//Senator senatorDetails =
//new Senator(senName, senParty, senState, senYears);
//System.out.println(senatorDetails);
}
}