help: writeObject is appendind data!

Hi, I am doing an app an d I need to save some configuration parameters, so I am using ObjectOutputStream and FileOutputStream, the problem is that each time I call to writeObject the configuration file is increasing and the data is being appended. But I dont want this.

my code is:

// on the constructor

try{

salidaArchivo=new FileOutputStream (path+"config.dat");

salidaDatos=new ObjectOutputStream (salidaArchivo);

}catch (Exception e){

e.printStackTrace();

}

// on my method

String data []=new String [5];

data [0]= txt_Configuracion_Puerto.getText();

data [1]= txt_Configuracion_Velocidad.getText();

data [2]= txt_Configuracion_Vendor.getText();

data [3]= txt_Configuracion_Path_Entrada.getText();

data [4]= txt_Configuracion_Path_Salida.getText();

if (data [0].compareTo("")==0){

data [0]="COM5";

}

if (data [1].compareTo("")==0){

data [1]="115200";

}

if (data [2].compareTo("")==0){

data [2]="Enfora";

}

if (data [3].compareTo("")==0){

data [3]=entrada;

}

if (data [4].compareTo("")==0){

data [4]=salida;

}

try{

salidaDatos.writeObject(data);

}catch (IOException e){

e.printStackTrace();

}

each time I call the method new data is appended. On the FileOutputStream I am not setting the appeding to true;

[2594 byte] By [MelGohana] at [2007-11-27 4:49:13]
# 1

If you do this:

open()

write()

write()

write()

then each write() will append. If you do this instead:

open()

write()

close()

open()

write()

close()

open()

write()

close()

then each open() will truncate the file to empty. I'm guessing you are doing the former and you want to do the latter? Change your code.

sjasjaa at 2007-7-12 10:02:17 > top of Java-index,Java Essentials,Java Programming...