Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 11336

Leitura de ficheiro txt e matriz

$
0
0
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; }

Viewing all articles
Browse latest Browse all 11336

Trending Articles