Ola bom dia, estou a tentar ler um ficheiro .txt e criar uma matriz de boolean que fica a true nas posiçoes com o a string "=" , mas estou com algumas dificuldades, o ficheiro é deste tipo
==========
= L L =
# *
# L *
# = =
# *
# k = *
= k *
# X *
==========
o que tentei foi:
public boolean[][] readToMatrix() throws FileNotFoundException{
Scanner sc = new Scanner(new File("Pasta/ficheiro.txt"));
String linha = "";
boolean[][] matriz = new boolean[10][10];
ArrayList<String> list = new ArrayList<String>();
while(sc.hasNextLine()){
linha = sc.nextLine();
list.add(linha);
}
sc.close();
int j = -1 ;
for(String k : list){
j++;
for(int i = 0 ; i < k.split("").length ; i++){
if(k.split("")[i] == "="){
matriz[i][j]== true;
}
else{
matriz[i][j]=false;
}
}
}
return matriz;
}
↧