Search code examples
javajava-menetwork-programmingmidp

How do I read strings in J2ME?


I'm using the MIDP 2.0 (JSR 118) and I just noticed that there is no reader for strings in J2ME.

Does anyone know how you are supposed to read Strings from an InputStream or InputStreamReader in a platform independent way (i.e. between two java enabled cell phones of different models)?


Solution

  • Alternatively have a look at DataInputStream.readUTF().

    It does required that the string being read off the InputStream be encoded appropriately (as in by a corresponding DataOutputStream.writeUTF(String)) so it might not be what you're looking for - but it does work across different phones/models etc.