i'm building my first android app i'm collecting 3 simple fields of data and then i will email them to a user.
i have the app up and running i can collect and display the data on the screen and i can also send the data via email. but the data is just being put on one line of text with know spaces.
i'm using FileOutputStream to write the data and i've added some text into the stream to breakup the data..but this doesnt seem to be the best route? what should i be doing? below is a sample with 2 of my fields and a static string of text.
it comes out like Balls: 22 i would like it to have spaces or headers. i guess i could add fos.write(" ".getBytes()); to make a space?
thanks
FileOutputStream fos = v.getContext().openFileOutput(file_name, MODE_PRIVATE);
fos.write("Balls: ".getBytes());
fos.write(balls.getBytes());
fos.write(strikes.getBytes());
fos.close();
Why not just construct the String(s) first and then call
getBytes()
on the resulting String and pass it to fos.write()
?
Example:
FileOutputStream fos = v.getContext().openFileOutput(file_name, MODE_PRIVATE);
String bigstring = "Balls: " + balls + " Strikes: " + strikes;
fos.write(bigstring.getBytes());
fos.close();
If you want to insert a newline into the String you can do it by concatenating a new-line character into it.