![]() ![]() ![]() Obtaining the Console instanceWe obtain the unique instance of the Console class via the static method console() of the System class like this: Console console = nsole() ![]() ("Hello " + name) by this one using the Console class: String name = console.readLine("Enter your name: ") Ĭonsole.printf("Hello %s ", name) As you can see, we can both read input and write output using this class conveniently.Now, let’s look at deeper into using this class. ("Hello " + name) Imagine you can shorten this piece of code: ("Enter your name: ") = new BufferedReader(new InputStreamReader(System.in)) This Java tutorial helps you understand the java.io.Console class which provides convenient methods for reading input and writing output to the standard input (keyboard) and output streams (display) in command-line (console) programs.As the Java platform evolves over the years, it introduces the Console class (since Java 6) which is more convenient to work with the standard input/output streams than the traditional approach (using System.in and System.out).Consider the following code before Java 6: BufferedReader standardInput ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |