Puoi tentare trasformando il tutto in un JSON Array (puoi farlo sia creando un nuovo file, sia facendolo in-memory). Ad esempio:
codice:
FileWriter fw = null;
BufferedWriter bw = null;
PrintWriter pw = null;
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader( ... ); // Percorso al tuo file
br = new BufferedReader( fr );
fw = new FileWriter("nuovo_file.txt");
bw = new BufferedWriter( bw );
pw = new PrintWriter( pw );
pw.print("\"pippo\":[");
String line = null;
StringBuilder sb = new StringBuilder();
while((line = br.readLine()) != null) {
if (sb.length() > 0) pw.println( sb.toString() );
sb.setLength( 0 );
sb.append( line ).append(",");
}
sb.deleteCharAt(sb.length() - 1);
sb.append("]");
pw.println( sb.toString() );
pw.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (br != null) {
try { br.close(); } catch (Exception e) { }
} else {
if (fr != null) {
try { fr.close(); } catch (Exception e) { }
}
}
if (pw != null) {
try { pw.close(); } catch (Exception e) { }
} else {
if (bw != null) {
try { bw.close(); } catch (Exception e) { }
} else {
if (fw != null) {
try { fw.close(); } catch (Exception e) { }
}
}
}
}
A questo punto hai un nuovo file che dovrebbe rappresentare un JSON Array valido in cui ogni elemento è un JSON Object corrispondente ad ogni tua riga.
Non l'ho testato, ma dovrebbe andare... va calibrato un attimo sull'ultima riga se il file termina con uno o più A-CAPO.
Ciao.