Author | Message |
---|---|
dliang
Posts: 35
|
Posted 21:23 Jan 30, 2020 |
Professor Kennan What should we do, when we having a line-feed(InputStream), should we skip it or jump into the next line. |
240812281
Posts: 7
|
Posted 21:25 Jan 30, 2020 |
you can use skip() to skip the line-feed since line-feed is 1 byte, so just use skip(1). same for space |
dliang
Posts: 35
|
Posted 21:35 Jan 30, 2020 |
|
dliang
Posts: 35
|
Posted 21:37 Jan 30, 2020 |
Maybe I can use Scanner |
240812281
Posts: 7
|
Posted 21:43 Jan 30, 2020 |
|
240812281
Posts: 7
|
Posted 21:44 Jan 30, 2020 |
Scanner only works for text IO if I remember correctly, anything related to binary IO we need to use the things we learned this week. |
ccasti26
Posts: 4
|
Posted 21:56 Jan 30, 2020 |
I used a method similar to the TestFileStream example in the book where '-1' is used to know when the end of the file was reached. Modify it so you looking for the white space character, not '-1'. When it reaches the white space, nothing will happen, so your next 'read' will be the character AFTER the white space! Edit: I listed the wrong example from the book. It should be more helpful now! Last edited by ccasti26 at
22:26 Jan 30, 2020.
|
dliang
Posts: 35
|
Posted 21:57 Jan 30, 2020 |
|
dliang
Posts: 35
|
Posted 21:59 Jan 30, 2020 |
|
kknaur
Posts: 540
|
Posted 13:35 Jan 31, 2020 |
All good suggestions. You can either skip(1) the new line character or if you are reading the entire line byte by byte (character by character), then you can stop at the end of the line when the current byte that is read is the value of the new line character (after casting to char of course). |