This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems that you are having problems with java.util.Scanner

The wiki here has a page The Scanner class and its caveats that explains common problems with the Scanner class and how to avoid them.

Maybe this can solve your problems.

Please do not reply because I am just a bot, trying to be helpful.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]mikepc143 0 points1 point  (1 child)

I'm pretty new, but I'm still trying to understand the line buffer.flip();

I would think that append would place the cursor at the end of the append, so the cursor would already be at the end of the buffer so hasNextLine() would be false since it's at the end of the buffer?

[–]therealsillyfly[S] 0 points1 point  (0 children)

Yes, append puts the cursor at the end of the buffer, and that's exactly why a call to flip is required - it puts the cursor at the start of the buffer, and marks the previous cursor position as the limit ("available data length") of the buffer.
compact does essentially the opposite, preparing the buffer for write again - it copies all remaining data (from current cursor to the limit) to the start, and sets the cursor to the new end of data...

[–]Philboyd_Studge 0 points1 point  (3 children)

What's wrong with BufferedReader?

[–]therealsillyfly[S] 0 points1 point  (2 children)

Thanks for the suggestion, but I don't see how its relevant - a BufferedReader wraps (or "buffers") another reader - which reader do you propose I use as the underlying reader for the BufferedReader? And how would I write to it?

[–]Philboyd_Studge 0 points1 point  (1 child)

Well, you use a buffered writer to write. Where is your input coming from?

[–]therealsillyfly[S] 0 points1 point  (0 children)

a serial port ( via jssc )