SuissoS Posted January 5, 2013 at 08:48 PM Report #489808 Posted January 5, 2013 at 08:48 PM (edited) Eu fiz este programa para passar uma matriz m para um ficheiro HTML em NetBeans. private static String escreverHTML(int x, int[][] m) throws FileNotFoundException { String format; format = "<table align='center'>"; for (int i = 0; i < x; i++) { format += "<tr>"; for (int j = 0; j < x; j++) { format += "<td>"; if (j == 0) { format += "["; } format += m[i][j]; if (j == x - 1) { format += "]"; } format += "</td>"; } format += "</tr>"; } return format; } No entanto agora tenho que o descodificar e da-me erro: public static int[][] lerHTML() throws FileNotFoundException { System.out.println("Digite o nome do ficheiro"); String nomedoficheiro = in.nextLine(); Scanner ficheiro = new Scanner(new File(nomedoficheiro + ".html")); String ficheirotxt = ""; while (ficheiro.hasNext()) { ficheirotxt += ficheiro.nextLine(); } ficheiro.close(); String[] table = ficheirotxt.split("<table align='center'>"); String[] tr = table[1].split("<tr>"); String[] barra = table[1].split("["); int[][] matriz = new int[table[1].split("<tr>").length - 1][tr[1].split("<td>").length - 1]; for (int i = 1; i < table[1].split("<tr>").length; i++) { String[] td = tr[i].split("<td>"); for (int j = 1; j < tr[1].split("<td>").length;j++) { matriz[i - 1][j - 1] = cortar(td[j]); } } return matriz; } private static int cortar(String line) { int devolve = 0; String[] splitted = line.split("</td>"); String troca = splitted[0].replace(",", "."); devolve = Integer.parseInt(troca); return devolve; } Edited January 5, 2013 at 10:29 PM by apocsantos geshi
HappyHippyHippo Posted January 5, 2013 at 11:08 PM Report #489841 Posted January 5, 2013 at 11:08 PM No entanto agora tenho que o descodificar e da-me erro: e que erro é ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now