DataOutputStream/DataInputStream

J

JScoobyCed

Hi,

I remember having read on this newsgroup that the use of
DataInputStream/DataOutputStream is not the best choice, as other
alternatives can be found.
I am not sure but that was linked to the readLine() method in particular.
Now I have found several tutorials for J2ME that use DataXXXputStream to
writeUTF and readUTF from/to a String. This is in particular to access
the mobile database (RMS package).
Is this a really good practice and safe to use those Objects ?
Thanks
 
S

Steve Horsley

JScoobyCed said:
Hi,

I remember having read on this newsgroup that the use of
DataInputStream/DataOutputStream is not the best choice, as other
alternatives can be found.
I am not sure but that was linked to the readLine() method in particular.
Now I have found several tutorials for J2ME that use DataXXXputStream to
writeUTF and readUTF from/to a String. This is in particular to access
the mobile database (RMS package).
Is this a really good practice and safe to use those Objects ?
Thanks

Have a good look at the javadocs for DataXXXputStream. You will find
that they write and expect a length indicator at the front of the string.
It is unlikely that your other end behaves the same way.

You may need to use String.getBytes(String characterset) and friends,
and read and write byte arrays instead.

Steve
 
M

Michael Borgwardt

JScoobyCed said:
I remember having read on this newsgroup that the use of
DataInputStream/DataOutputStream is not the best choice, as other
alternatives can be found.

It always depends on what you want to do.
I am not sure but that was linked to the readLine() method in particular.

If you have text-only data, then the Reader/Writer classes are better.
Now I have found several tutorials for J2ME that use DataXXXputStream to
writeUTF and readUTF from/to a String. This is in particular to access
the mobile database (RMS package).
Is this a really good practice and safe to use those Objects ?

If you have binary data with some text fragments embedded, then it is a
good choice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top