Re: datainput stream

From: Raymond DeCampo (rdecampo_at_spam-I-am-not.twcny.rr.com)
Date: 12/13/03


Date: Sat, 13 Dec 2003 03:36:36 GMT

Amey Samant wrote:
> hi chris
>
> your explanation certainly made my basic concepts solid
> though i could actually figure out what went wrong with the help of
> one of my friend, your explanation deserves appreciation :)
> as i also mentioned previous post that i got confused by the return
> type of readInt ....
> i should have read the docs carefully :) but then i would have missed
> this entire conversation :D
> i will also keep in mind about the '\n' and '\r' on win while only
> '\n' on nix
>
> so if you have to write "real platform independent" code which uses
> DataInputStream you must first get platform type and then write if
> else to deal with \n \r thing :D
> what you say
> sounds like #if #elif code in c :D

Java provides tools to help you deal with this in a sane fashion. For
example, BufferedReader will read a line and handle the '\n' or '\r\n'
issue for you. (Although I understand that it has problems on Mac
platforms, where the line separator is '\r'.)

For writing data, use the PrintStream or PrintWriter (actually, use
PrintWriter if at all possible), which have println() methods that will
append the proper line terminator.

Finally, if you need to know the line separator on the platform for any
reason, use System.getProperty("line.separator").

Please, please, please do not use any #if or #elif like expressions.
They give Java coders headaches. :)
Seriously, with the above tools I mentioned, you should be able to write
line handling code that looks elegant, is easy to maintain and is usable
on any platform.

Ray



Relevant Pages

  • Re: Excellent Website for Survivor Fans
    ... went back up on the platform to look for it again from above. ... swim anymore. ... Jonathan had a great explanation of the Yau Man vote off. ...
    (alt.tv.survivor)
  • Re: Excellent Website for Survivor Fans
    ... went back up on the platform to look for it again from above. ... swim anymore. ... Jonathan had a great explanation of the Yau Man vote off. ...
    (alt.tv.survivor)
  • Re: Excellent Website for Survivor Fans
    ... went back up on the platform to look for it again from above. ... swim anymore. ... Jonathan had a great explanation of the Yau Man vote off. ...
    (alt.tv.survivor)
  • Re: OT: Mind the step!
    ... provide an explanation? ... I have the answer to the first question, ... And has the platform been divided into two parts, one for Talgo trains ...
    (uk.railway)