Ciao,
ho implementato una funzione che leggendo un certo file mi crea all'interno di uno nuovo, le stesse righe del file di testo aggiungendo una stringa in un punto preciso, pero' ho alcuni problemi in fase di lettura (credo)...
Questo è il codice della mia funzione dove, il metodo "getTagsBaseName()" mi dovrebbe restituire una stringa creata in precedenza, ed andarla ad inserire nel nuovo file...
Questo è invece il file preso in input:codice:public class ReadWriteTemp { MainArray ma = new MainArray(); String TopicLine = "<resourceData>Topic Di Bamberg Symphony</resourceData>"; public ReadWriteTemp() { BufferedReader br = null; BufferedWriter bw = null; try { br = new BufferedReader(new FileReader("TapsasConcerts_Bamberg.xtm")); } catch (FileNotFoundException e) { System.err.println("File Tapsas Concerts Bamberg not found!"); System.exit(1); } try { bw = new BufferedWriter(new FileWriter("out.xtm")); } catch (IOException e) { System.err.println("Error opening out.txt!"); System.exit(1); } try { while(br.ready()) { String inLine = br.readLine(); if(inLine.equals(TopicLine)) { bw.write(ma.getTagsBaseName()); bw.newLine(); } bw.write(inLine); bw.newLine(); } } catch (IOException e) { System.err.println("Error reading or writing!"); System.exit(1); } try { br.close(); bw.close(); } catch (IOException e) { System.err.println("Error closing!"); System.exit(1); } } public static void main(String args[]) { new ReadWriteTemp(); } }
In sostanza dovrei inserire un stringa del tipo:codice:<?xml version="1.0" encoding="utf-8" standalone="yes"?> <topicMap xmlns="http://www.topicmaps.org/xtm/1.0/" xmlns:xlink="http://www.w3.org/1999/xlink" id="id0"> <topic id="id596"> <instanceOf> <topicRef xlink:href="#id2"></topicRef> </instanceOf> <occurrence> <instanceOf> <topicRef xlink:href="#id7"></topicRef> </instanceOf> <resourceData>2006-12-14</resourceData> </occurrence> <occurrence> <instanceOf> <topicRef xlink:href="#id5"></topicRef> </instanceOf> <resourceData>I picked this concert from a program of events that Erika had waiting for us when we arrived for a five-day pre-Christmas visit and we managed to get tickets for the four of us. The Meistersingerhalle is enormous and in the fourth row of the balcony the orchestra feels miles away. Fortunately the acoustics are quite good. I found Blomstedt's tempi to be a bit on the slow side: it's as if he loves the music so much he doesn't want it to ever end, but I would have preferred a bit more forward motion and - given the size of the hall - a bit more power as well. Nevertheless, a very enjoyable concert.</resourceData> </occurrence> <occurrence> <instanceOf> <topicRef xlink:href="#id61"></topicRef> </instanceOf> <resourceData>Topic Di Bamberg Symphony</resourceData> </occurrence> </topic>
<baseName>
<baseNameString>Bamberg Symphony 2006-12-14</baseNameString>
</baseName>
all'interno del mio Topic...![]()

Rispondi quotando