While readline null




















Home Java How to solve infinite readLine while. UcanaccessDriver visits Adding methods to es6 child class visits All popular answers. The error was: error while evaluating conditional.

Placing the :before-value in the same way as a list-item is placed? Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up. Connect and share knowledge within a single location that is structured and easy to search. I want to refactor the following code because I don't feel comfortable about using assignment inside comparison operator. It looks like pretty idiomatic C, but do you think this is a good practice in Java?

It seems that opinions on whether it's OK or not are divided. However, both Guava and Commons IO provide alternative solutions for this issue.

If I had any of these libs in the current project, I'd probably use them instead. Assignment inside a condition is ok in this case, as the assignment is surrounded by an extra pair of parentheses — the comparison is obviously! Alternatively, we could do this which also restricts the scope of line as with the for -loop, and additionally eliminates unnecessary repetition:.

You could increase the abstraction level of the code a little bit with an iterator-like pattern and the same time you could reuse an existing library with the experience of the authors for that: Apache Commons IO LineIterator. Using an iterator hides an unnecessary detail: the reader returns null when there is no more data.

The hasNext method is closer to the English language, the code is easier to read. This answer and question contain an expressive example. See also: Effective Java, 2nd edition , Item Know and use the libraries The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too. Instead of wrapping the reader in an iterator, you could also wrap it in an Iterable that then returns the iterator. Asked 1 year, 3 months ago.

Active 1 year, 3 months ago. Viewed times. It works like when a message was sent run the code This is my server code It's not an infinite loop. Basically, what it's doing is that it keeps on reading until it detects that there is no input. Which means that when reading from a socket, the loop will end when the socket is closed by the remote party. Add a comment. It also redirects the standard output from the console to the output file.

It then uses the Console. ReadLine method to read each line in the file, replaces every sequence of four spaces with a tab character, and uses the Console. WriteLine method to write the result to the output file. The ReadLine method reads a line from the standard input stream. For the definition of a line, see the paragraph after the following list. This means that:. If the standard input device is the keyboard, the ReadLine method blocks until the user presses the Enter key.

One of the most common uses of the ReadLine method is to pause program execution before clearing the console and displaying new information to it, or to prompt the user to press the Enter key before terminating the application. The following example illustrates this. If standard input is redirected to a file, the ReadLine method reads a line of text from a file.

For example, the following is a text file named ReadLine1. The following example uses the ReadLine method to read input that is redirected from a file.



0コメント

  • 1000 / 1000