• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How I can preserve an string "new line" characters when it converted into byte array?

 
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post
I have an string like

This is
My new
Car.


I should convert it to an inputStream in otder to be able to use that stream in an API
I use following code to convert the string to inputStream




Now when i use this byteArray it removes all of my new line characters (enter) and all of my words come one after another.

I found it after several hours of hard works to figure out what is wrong with the API, How i find that bytearray removes all New Line (enter) characters?
I find it by writing the content of the above array into a file

code snippet that i used to write the array into the file is like:



Can you tell me how i can preserve those New Line (enter) characters after each line?
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it doesn't remove new-lines. However, the way that Java wrote out the new-lines may not match the new-line convention used by your editor.

You may find it useful to look at the file in a hex editor (I'd use hexl-mode in emacs, but you're probably not using emacs, so choose your own way of viewing a file in hex).

Perhaps post the hex dump of a file for a small string here. Also, please tell us what your operating system is.

Also, how did you get the data into your string? How do you know it actually contains new-lines?
[ September 04, 2007: Message edited by: Peter Chase ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that this is really the case? How do you know it removes the newlines? I wrote the following test program, and in the output file (C:\out.txt) the newlines are not missing.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic