Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

quick question: bufferedreader  RSS feed

 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you read() a character in the buffer, how do you check for end of line? is it null. just need to make sure. thanks.

nikita
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
return -1 for end of line, the API says this
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K. Tsang:
return -1 for end of line, the API says this


A -1 is for the end of stream -- not end of line. Line are terminated with either a linefeed and/or carriage return -- which are valid ASCII characters that will be returned.

Henry
 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so why can't i capture the end of line? the BufferedReader.java file has a private field skipLF. i'm assuming this is causing the behavior. is there a way to get around it?



i tried testing for (c == 10) as well. any ideas?
 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
someone gave me a hint: line feed '\n' are treated as whitespace. so:



kinda nice huh?
 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a question on using BufferedReader's mark(), reset(), and read().
if i have input like:

45 href 12: 2 http

i know that mark() is a bookmark in the stream that reset() will return to. i just need an example. thanks.

n.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by f. nikita thomas:
[QB]so why can't i capture the end of line?

If you want to read one line at a time you can use the method readLine()
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by f. nikita thomas:
i have a question on using BufferedReader's mark(), reset(), and read().
if i have input like:

45 href 12: 2 http

i know that mark() is a bookmark in the stream that reset() will return to. i just need an example. thanks.

n.


There is a policy(UseOneThreadPerQuestion) here in javaranch that discourages posting multiple questions in a single thread. It also decreases the chances of you getting an answer because many ranchers open the topic that has an interesting description or the field that is of interest to them.
You can post this question in a seperate thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!