| Author |
Problems inserting new line in txt J2me
|
Andre Simoes
Greenhorn
Joined: Aug 18, 2011
Posts: 3
|
|
hello!
J2me code below is to get the data from the InputStream with txt and insert them back into the OutputStream to txt with the new data from TextField, but it stores only the first letter of the txt and not all data from the txt, below will the code and an example of the output txt.
Below the informationin txt before executing the code
andre-1491254172-Male
Now down information in txt after the execution of the code (the data were in TextField Name: john, Phone: 1491257777, Sex: Male)
a
john-1491257777-Male
As you can see it seems the InputStream is read only the first letter of txt, in the case "a" word "andre" and not all data within.
Does anyone know what is wrong with the code?
The intention was to insert more data into txt, but in line below, each data record inserted in the last row available, and the way I found was this store and read everything put back in txt concatenating the new information from the TextField and ChoiceGroup.
tks vm!!!
|
 |
Walter Gabrielsen Iii
Ranch Hand
Joined: Apr 09, 2011
Posts: 158
|
|
There's nothing wrong per say. Your input stream is doing exactly what you report -- returning a single byte, in the form of a character.
The read() on InputStream in Java ME's API verifies this: "Reads the next byte of data from the input stream." and "If no byte is available because the end of the stream has been reached, the value -1 is returned."
So, if you want to read more than one piece to come in, you need a while loop, to continue until it finds -1. I'm pulling this snip-it example from Java SE's Character Streams example, so it isn't really useful for Java ME, except that it shows a while loop similar to what you need to use to test for the -1 end condition:
|
 |
Andre Simoes
Greenhorn
Joined: Aug 18, 2011
Posts: 3
|
|
Walter,
perfect, I could solve my problem with your code base.
Tks vm.
|
 |
 |
|
|
subject: Problems inserting new line in txt J2me
|
|
|