So i am working on a java project for my first semester programming class and I have code here with an error I am stumped on.
The user will input the file name containing equipment information from the terminal. The program will read from the file and put the lines into a tokenizer which will separate the tokens in accordance to commas.
My current code:
import java.util.*;
import java.io.*;
public class Project4
{
public static void main(String args[]) throws FileNotFoundException
{
String fix;
Scanner in = new Scanner(System.in);
System.out.println("Welcome to Transport Canada");
System.out.print("Please enter text file: ");
String filename = in.nextLine();
File file = new File(filename);
Scanner inp = new Scanner(file);
fix = MTBF(inp);
System.out.println(fix);
inp.close();
}
public static String MTBF(String fixing)
{
StringTokenizer strTokenizer = new StringTokenizer(fixing, ",");
while(strTokenizer.hasMoreTokens())
{
fixing = strTokenizer.nextToken();
}
return fixing;
}
}
The input file looks like this:
Secondary,456,3:2011,1,1,4,1
Primary,457,4:2011,2,0,2,2
Backup,458,5:2011,10,11,4,3
So where are my errors, what am I doing wrong and most importantly...HOW FIX!?
Thank you for your time