java - How would I read the following text into a 2D Array -
The 2D object once written in the text file looks like this:
null Null-5 160 2 empty redundant 75 80 1 75 160 Faucet 75 320 1 Faucet faucet 155 160 2 Faucet 235 0 1 235 80 2 235 160 1 In the empty null
The object is in the form
element (x, y, i)
So each object uses 3 digits.
The problem occurs in reading intriggers from a text file because it is mixed with "zero values" with the string. This is what I have done so far, but it only reads the text file partially.
Public Zero Read Elements () throws IOException {file file = new file ("elements.txt"); Scanner inp = new scanner (file); (Ifp.hasNextLine ()) {inp.nextLine (); (for int col = 0; col & lt; rectArr.length; col ++); } (Int line = 0; line & lt; rectArr [0]; length; line ++) {if (inp.hasNext ()) {try {string s = inp.next ()} Integer.parseInt ); Println (s); Int x = integer. Press (s); Int y = integer .presscent (inp.next ()); IntI = Integr .Presscent (inp.next ()); Elementarre [cola] [row] = new element (x, y, i); } Hold (number format expiry enfee) {}}}}}
Comments
Post a Comment