Gemalto is now part of the Thales Group, find out more.

You are here

Terminal TC65: how to avoid data appended in file? | Thales IoT Developer Community

June 18, 2015 - 5:19am, 2068 views

I am using addFile() method --see below-- in order to create a file in TC65 Terminal  to saved a value 
 from servlet.I don’t have any problem to write  one digit in file if the previous data saved is one digit too

but if have to write one digit and I have two digit previously saved this problem appears.
Example:
16 is the number in file saved and 3 is the new number I should get from servlet.The result I saved is 36
I presume the problem is here:

objOutputStream.write(String.valueOf(mensaje).getBytes())

 

write(byte[])

b(0), b(1).. This vector is the reason to have data appended.  I don't know how to do a buffer refresh or something like this before saving the new data to avoid the problem I am having.Any help would be great.

Regards.

German F

public void addFile(){

        FileConnection objFileConnection = null;

    try {

        objFileConnection = (FileConnection) Connector.open("file:///a:/dataServlet.txt");

    } catch (IOException ex) {

        ex.printStackTrace();

    }

 if(!objFileConnection.exists())

    

     try {

     objFileConnection.create();

        } catch (IOException ex) {

            ex.printStackTrace();

        }

    try {

        OutputStream objOutputStream=objFileConnection.openOutputStream();

        objOutputStream.write(String.valueOf(mensaje).getBytes());

        objOutputStream.flush();

        objOutputStream.close();

    } catch (IOException ex) {

        ex.printStackTrace();

    }

 

  }