S
sevedaja
hello
I¡¦ve recently started learning Java ( and programming in general ),
but it's not that easy.
1) According to System.getProperty("line.separator"); on windows
systems newline is represented by CR+LF. Then why, when reading from
standard input ( keyboard ) and pressing enter, the only character
read is CR ( \n ), but not also LF (¡¥\r¡¦):
InputStreamReader is = new InputStreamReader ( System.in );
int i1 = fr.read(); // after pressing enter, i1 equals 10
int i2 = fr.read(); // after pressing enter, i2 equals 10
2) As I understand it, when java writes ¡¥\n¡¦ to the output stream, it
doesn¡¦t translate this character into platform dependent newline
sequence ( CR + LF „³ ¡¥\n¡¦ + ¡¥\r¡¦ )? Same when writting ¡¥\r¡¦ to the
output stream.
So if we want to write to a certain type of file, then we must know
beforehand which character ( or sequence of characters ) represent
newline in this file, else text editor or word processor, used to
display this file, won¡¦t be able to display it correctly ( if nothing
else, the whole text will be on only one line )?
3)I assume each of word processors or text editors running on same
platform ( like windows ) can use different character sequences for
newline (notepad for example doesn¡¦t use CR+LF for newline, but
instead uses LF+CR)?
So if each program running on top of windows can use different
characters to represent newline, then why would Java programmer need
to know platform¡¦s native newline representation?
4)Are there any Java write()methods, that do convert ¡¥\n¡¦ ( or ¡¥\r¡¦ )
into platform dependent newline?
I hope you can help
thank you
I¡¦ve recently started learning Java ( and programming in general ),
but it's not that easy.
1) According to System.getProperty("line.separator"); on windows
systems newline is represented by CR+LF. Then why, when reading from
standard input ( keyboard ) and pressing enter, the only character
read is CR ( \n ), but not also LF (¡¥\r¡¦):
InputStreamReader is = new InputStreamReader ( System.in );
int i1 = fr.read(); // after pressing enter, i1 equals 10
int i2 = fr.read(); // after pressing enter, i2 equals 10
2) As I understand it, when java writes ¡¥\n¡¦ to the output stream, it
doesn¡¦t translate this character into platform dependent newline
sequence ( CR + LF „³ ¡¥\n¡¦ + ¡¥\r¡¦ )? Same when writting ¡¥\r¡¦ to the
output stream.
So if we want to write to a certain type of file, then we must know
beforehand which character ( or sequence of characters ) represent
newline in this file, else text editor or word processor, used to
display this file, won¡¦t be able to display it correctly ( if nothing
else, the whole text will be on only one line )?
3)I assume each of word processors or text editors running on same
platform ( like windows ) can use different character sequences for
newline (notepad for example doesn¡¦t use CR+LF for newline, but
instead uses LF+CR)?
So if each program running on top of windows can use different
characters to represent newline, then why would Java programmer need
to know platform¡¦s native newline representation?
4)Are there any Java write()methods, that do convert ¡¥\n¡¦ ( or ¡¥\r¡¦ )
into platform dependent newline?
I hope you can help
thank you