Hello, in this video, we are going to show a very simple example of getting input from the user via the console. We showed console output using the system print out method. And that's pretty cool. But we might, you know, want to actually get some input from the user in the console and the data extremely simple. So we need to import a couple of files. So import java.io dot buffered, the buffered preferred.
Burger dub preferred reducto. This import just allows us to include this, you know, class, this module this functionality within Java. It allows us to use all the code I've mounted because it's saying it's on used, but we'll be using that very soon. On importing number one All the.io the audio and we need one last one, I promise import java.io dot input need. Okay, so that's all of them done. So this allows us to, you know, get content, you know, from the buffer.
This, the input stream reader is, you know, allowing us to actually get input, and it's stored in a buffer. io exception is required because you need to throw an exception when you use this method. So the first thing we're gonna do throws IO exception just in case something were to go wrong. It will just throw an input exception. Okay, so to actually read it, let's do buffered reader and we'll name it Read up very descriptive you often need so we're creating a BufferedReader object like seven he creates another new object called input reader and this takes in system dot like so, for some colon up there and I will close it down a bit or DC. So, I thought you can see this a little better.
And now that will I can read now the input will but we need to actually read the and store it somewhere. We can read it using reader dot read line, but we need to store it into a variable. It always has to be a variable you can convert this a later date if you know like a number for example, we need to store in a variable so reader is next string name equal reader dot read redline. So I'm finally we can do anything we want with this. Now we could print it out, and a system printer because when it's when a variable manipulated however we want. And we're just going to do a simple System dot out dot print ln, our favorite little method.
Name here, run it. So nothing that period, but this actually halted the console. And if you're waiting for us, we've done this reader dot read line. So it's basically saying no, wait till we get some input, I put my name on, press enter, I think you can see it, got it, and it printed it out in here. So that's it very simple to read input from the user via the console in Java. If you have any questions, feel free to reach out.
All the source code from this video and every other part in the series will be available by the GitHub link. And as usual, thanks for watching and I look forward See you in the next awesome Java tutorial.