Question
***In Java*** I am trying to loop through a file until the end is reached but I am having trouble. here is my code:( Bolded
***In Java*** I am trying to loop through a file until the end is reached but I am having trouble.
here is my code:(Bolded code is the loop i need help with)
public class BoardGame {
private int board_length; private int board_width; // private Snake theSnake; private String[][] matrix; private String buffer = null;
public BoardGame(String boardFile) { MyFileReader in; in = new MyFileReader(boardFile); int value1 = in.readInt(); int value2 = in.readInt(); board_length = in.readInt(); board_width = in.readInt(); int intialRow = in.readInt(); int intialCol = in.readInt(); // theSnake = new Snake(initialRow, initialCol); matrix = new String[board_length][board_width]; for (int i = 0; i < board_length; i++) { for (int j = 0; j < board_width; j++) { matrix[i][j] = "empty"; } }
while (in.hasNextLine()){ matrix[in.readInt()][in.readInt()] = in.readString(); }
} However this is not working. the format of the file after the first 6 lines is int,int,string,int,int,string and so on.
MyFileReader is a BufferedReader is that makes any difference.
Thanks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started