Adding Data to Files from Java with Siemens-Cinterion Modems
Posted by blogElectronica in 2.DISPOSITIVOS (práctico), 4.PROGRAMACIÓN, Comunic. GSM/GPRSOn several occasions I have been asked how to add more data to an existing file in the flash memory of our TC65 or XT65 modems (or MTX terminals from Matrix). So today I am going to post a small Java program to help those of you who don’t know how to do this. It’s very simple.
Basically you use the OutputStream object instead of the DataOutputStream (DataOutputStream comes from OutputStream) which I’m sure you saw in the post where the majority of the Java examples are.
Let’s look at a little example today. Let’s assume that we have a file in the modem’s file system called ”A:/file.txt“ with the text “hola”. If you don’t have one, make one and put it in the modem.
/* Create an object in the FileConnection class and specify the name of the file to open, which will be file.txt*/
FileConnection objFileConnection = (FileConnection)
Connector.open(“file:///a:/file.txt”);/*Check the current file size*/
long fileSize=objFileConnection.fileSize();/*Create an object in the OutputStream class. With this we can write data in the file and pass it off as a current file size parameter so that the file writing “pointer” is at the end of the file.*/
OutputStream objOutputStream = objFileConnection.openOutputStream(fileSize);/*Write the text “Adios” inside the file that we have just opened (or created)*/
objOutputStream.write(“adios”.getBytes());/*Send it writing everything that’s left in the buffer prior to closing it*/
objOutputStream.flush();/*Close the object*/
objOutputStream.close();/*Close the file*/
objFileConnection.close();
Once you run the application, if you look at the flie.txt contents you will see that the contents include “holaadios” i.e. it doesn’t overwrite the contents that’s already in the file, it adds the data.
To summarize, I will put up a few posts about two new terminal models, the MTX65+Gv3 (GPRS terminal modem with GPS) and the new MTX65-ULP (GPRS ultra low power modem). Firstly we will look at their features and then I will go into more detail about programming both devices, paying attention to the peculiarities of each one so that everyone will know exactly how to use them. I’m sure you’ll like it. This will be in a few days time.
I hope it’s been interesting for you.
Tags: cinterion, ejemplo java, j2me, java, mtx65, Siemens, tc65, xt65