Salve ragazzi, colgo l'occasione per presentarmi a tutti.
Sono generalekamikaze, studente della facoltà di Informatica e newbbie nella programmazione.
Stò cercando di scrivere un programmino, che, letto un file html (di base per eBay, per intenderci), vada a sostituire degli elementi generici, prendendoli da un altro file apposito.
Il programma che o messo su, seppur non completo, sembra in parte svolgere il suo lavoro, se non per il fatto che il nuovo file creato, non ha la stessa lunghezza del file generico, bensì viene tagliato.
Forse c'è un limite di righe per i file di testo scritti???
Ecco a voi il codice:
codice:import java.io.* ; /** * Classe utile a creare inserzioni ebay. * * @author generalekamikaze * */ public class Inserction { private final int LINES = 6; private final int LINES_GEN = 100; private final String SUB1_1 = "#titolo#"; private final String SUB1_2 = "</p>"; private final String SUB1_3 = "\n"; private final String SUB2_1 = "#comaptibile#"; private final String SUB2_2 = "</span></p>"; private final String SUB2_3 = "\n"; private final String SUB3_1 = "#descr#"; private final String SUB3_2 = "</td></tr></tbody></table></p>"; private final String SUB3_3 = "\n"; private final String SUB4_1 = "<a href=\""; private final String SUB4_2 = "#link2#"; private final String SUB4_3 = "\" target=\"_blank\"><img src=\""; private final String SUB4_4 = "\" height=\"108\" /></a>\n"; private final String SUB5_2 = "#link3#"; private final String SUB5_3 = "\" height=\"108\" /></a> \n"; private final String SUB6_1 = " <img style=\"width: 182px; height: 256px; top: 16px; left: 208px;\" src=\""; private final String SUB6_2 = "#link1#"; private final String SUB6_3 = "\"></p></div>\n"; private final String SUB1 = SUB1_1 + SUB1_2 + SUB1_3; private final String SUB2 = "SUB2_1 + SUB2_2 + SUB2_3"; private final String SUB4 = SUB4_1 + SUB4_2 + SUB4_3 + SUB4_2 + SUB4_4; private final String SUB5 = "SUB4_1 + SUB5_2 + SUB4_3" + SUB5_2 + SUB5_3; private final String SUB3 = "SUB3_1 + SUB3_2 + SUB3_3"; private final String SUB6 = "SUB6_1 + SUB6_2 + SUB6_3"; private final int FIRST_LINE = 15; private final int SECOND_LINE = 18; private final int THIRD_LINE = 20; private final int FOURTH_LINE = 28; private final int FIFTH_LINE = 29; private final int SIXTH_LINE = 30; public Inserction() { } private int numInserction(File text){ int result = 0; try{ int cont = 0; FileReader reader = new FileReader("input.txt"); BufferedReader in = new BufferedReader(reader); while(in.readLine()!=null) cont++; result = cont / LINES; }catch(IOException e){ System.out.println("General Error"); } return result; } private String[] takeVar(String text){ String[] var = new String[LINES]; try { FileReader fr = new FileReader(text); BufferedReader inFile = new BufferedReader(fr); for(int i = 0; i <= LINES -1; i++) { var[i] = inFile.readLine(); } inFile.close(); } catch (FileNotFoundException exception){} catch (IOException exception){} return var; } private void subInGen(String[] var,String path) { try { FileReader fr = new FileReader(path); BufferedReader inFile = new BufferedReader(fr); FileWriter fw = new FileWriter("D:/eBay/" + var[1] +".txt"); BufferedWriter bw = new BufferedWriter(fw); for(int i = 1; i <= LINES_GEN ; i++) { String readLine = inFile.readLine(); if( i == FIRST_LINE ) { readLine = readLine.replaceAll(SUB6_2, var[0]); bw.append(readLine); bw.newLine(); } else { bw.append(readLine); bw.newLine(); } } inFile.close(); } catch (FileNotFoundException exception){} catch (IOException exception){} } public static void main(String[] args) { Inserction a = new Inserction(); String esempio = "D:/eBay/lista.txt"; String path = "D:/eBay/gen.txt"; String[] take = a.takeVar(esempio); a.subInGen(take,path); for (int i = 0; i<= take.length - 1;i++ ) { System.out.println(take[i]); } } }

Rispondi quotando


