Till now, you created programs that take inputs from users. But what if you want to read a text or numbers from a file on your computer? You can use some internal libraries in Java to read from files.
Now let’s learn how to code reading text from file.
For this lecture, you will need to download the following text file and store it in a directory.
Note: Right click on the file below and click on "save link as" to save the file.
You may download the codes used in the video from below:
You now know how to read lines and words from a file. Let’s now read some numbers and use them in the code.
You can download the file used in the video — that contains the numbers — from below.
Note: Right click on the file below and click on "save link as" to save the file.
You can download the code used in the video from below:
In this lecture, you learnt how to read the files in your code. This could be useful if you have to write a code for text analysis. You could also use what you learnt to read numbers from files and then calculate the desired metric.