Boa Tarde!
public static void ficheiro() {int n=0; boolean i=false; do{ try{ n = Integer.parseInt(JOptionPane.showInputDialog("Introduza o tamanho de matriz de adjacências:")); i=true; } catch (Exception e){ JOptionPane.showMessageDialog(null, "Valor inválido, por favor introduza um valor inteiro..."); i=false; } } while(i==false); Scanner ficheiro = null; String nome, a; String [] temp = new String[n]; String [][] matrizf = new String [n][n]; int [][] matriz = new int [n][n]; nome = JOptionPane.showInputDialog(null,"Introduza o nome do ficheiro que contém a matriz:","Nome do Ficheiro",JOptionPane.QUESTION_MESSAGE); boolean file=false; do{ try{ ficheiro = new Scanner(new File(nome+ ".txt")); file=true; } catch(FileNotFoundException e){ JOptionPane.showMessageDialog(null,"O ficheiro escolhido não existe..","Ficheiro Inexistente",JOptionPane.ERROR_MESSAGE); file=false; } } while(file==false); System.out.println(ficheiro); while(ficheiro.hasNext()) { for(int l=0;l<n;l++) { a=ficheiro.nextLine(); temp= a.split(";"); if (temp[n-1]!=null) for(int c=0;c<n;c++) { matrizf[l][c]=temp[c]; matriz[l][c]= Integer.parseInt(temp[c]); } } } for (int l=0; l<n; l++){ for(int c=0; c<n; c++) { System.out.println(matriz[l][c]); } } }</blockquote>tenho aqui um problema…
a matriz não é imprimida, pois dá um erro na parte de leitura… alguém sabe o que é?
e já agora, dá também um erro na excepção que faço ao ficheiro pois, encontra quando não encontra o ficheiro, em vez de pedir novamente o nome, está sempre a apresentar a mensagem de erro (“Ficheiro não existe”)…
Se alguém me puder ajudar, agradecia
Obrigado
