G
Guest
Gast
Mein Programm schreibt in eine Datei. Es soll verschiedene Datensätze jedoch untereinander schreiben und nicht an desn bestehen einfach nach rechts anhängen.
Code:
public void PrtDet() {
try {
BufferedReader in2 = new BufferedReader(new FileReader("AFI.DE1"));
BufferedWriter out = new BufferedWriter (new FileWriter ("AfiOutput.txt"));
String satz2, inno, strmano;
int idx;
boolean foundObj = false;
while((satz2 = in2.readLine()) != null) // Loop1
// Read Input File while not eof
{
try {
strmano = satz2.substring(6,12);
if (strmano.equals("A MANO")) {
// Check Object
inno = satz2.substring(13,19);
foundObj = false;
idx = 1;
System.out.println("Suche Objekt " + inno + " in Array...");
for (idx = 1; idx < records; idx ++) {
// Search Inno in Array
//* System.out.println("Vergleiche " + arrayinno[idx] + " mit " + inno);
try
{
if (arrayinno[idx].equals(inno)) {
//* System.out.println("Objekt " + inno + " in Tabelle gefunden!");
foundObj = true;
//* System.out.println("Variable foundObj: " + foundObj);
//* System.out.println("------------------------------");
break;
}
}
catch(NullPointerException npe) {}
} // for (idx = 1; idx < records; idx ++)
} // if (strmano.equals("A MANO"))
if(foundObj == true) {
// Print Detail Records for Object
//*System.out.println("Print Detail for Objekt.. " );
while((satz2 = in2.readLine()) != null)
// Print Detail Records for Object
{
out.write(satz2);
out.flush();
System.out.println(satz2);
try {
strmano = satz2.substring(6,12);
if (strmano.equals("E MANO")) {
break;
}
}
catch(StringIndexOutOfBoundsException s) {}
catch(NullPointerException npe) {}
} // Loop End
foundObj = false;
System.out.println("E N D E: " + "Objekt: " + "-----------");
System.out.println(" ");
}
}
catch(StringIndexOutOfBoundsException s) {
}
}
out.close(); // close File
in2.close(); // Close File
}
catch(FileNotFoundException fnfe) {
System.out.println("Datei nicht gefunden!");
}
catch(IOException ioe) {
System.out.println("Fehler beim Lesen!");
}
}