I have txt file consists of ascii image (sample shown below) that I am trying to pass into a 2d array of unknown size which means I do not know the size of [row]
and [col]
.
I have found so many things but none have worked for me.
I have tried to adapt the things I read to make it work for my code but no progress. Please consider helping. Note I am doing this inside a class AsciiImage.
ArrayList<String>[][] arrayOfCharacters = new ArrayList[20][20];
public AsciiImage(String passFile) throws FileNotFoundException, IOException{
try{
Scanner input = new Scanner(new File(passFile));
int row = 0;
int column = 0;
while(input.hasNext()){
String[] c = input.nextL();
arrayOfCharacters[row][column] = c.charAt(0);
column++;
// handle when to go to next row
}
input.close();
} catch (FileNotFoundException e) {
System.out.println("File not found");
// handle it
}
Here is the txt file I am working on.
.'| .8
. | .8:
. | .8;: .8
. | .8;;: | .8;
. n .8;;;: | .8;;;
. M.8;;;;;: |,8;;;;;
. .,"n8;;;;;;: |8;;;;;;
. .', n;;;;;;;: M;;;;;;;;
. ,' , n;;;;;;;;: n;;;;;;;;;
. ,' , N;;;;;;;;: n;;;;;;;;;
. ' , N;;;;;;;;;: N;;;;;;;;;;
.,' . N;;;;;;;;;: N;;;;;;;;;;
.. , N6666666666 N6666666666
I , M M
---nnnnn_______M___________M______mmnnn
"-. /
~~~~~~~~~~~@@@**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>.