How would I implement Bufferedreader to read in a file with multiple fields? I understand that br reads line by line, but the format of the file is making it difficult for me to understand because each line varies in length. Here is an example of the text format. How do I get bufferedReader to interpret the 4 variable line every time it occurs? Then the 2 variabled lines that proceed afterward?
var0// number of test cases
var1 var2 var3 var4
num1 num2
num3 num4
... ...
... ...
var6 var7 var8 var9
... ...
... ...
...
...
Here is my basic BufferedReader code that reads the file
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class FileHandling {
public static void main(String[ ] args) {
Scanner scanner = new Scanner(System.in);
BufferedReader br = null;
String line;
//System.out.println("New.txt");
try{
br = new BufferedReader(new FileReader("Part1.txt"));
} catch (FileNotFoundException fileex) {
System.out.println(fileex.getMessage() + "This File Was Not Found");
System.exit(0);
}
//Read the lines
try {
while((line = br.readLine()) != null){
System.out.println(line);
}
} catch (IOException ioex) {
System.out.println(ioex.getMessage() + "Error Reading File");
}finally {
System.exit(0);
}
}
A few things to note. I understand this website and its uses. I've thoroughly researched for hours through other similar questions on this site. I've tried khan academy, youtube, everything I could think to solve my issue. I'm not looking for anyone to do my work for me. I'm just a lost CS student looking for tips in the right direction. My java skills are weak so maybe I'm just not approaching the problem in a way some one else could explain better. I appreciate any advice you all can give me. Thanks.