1. First, let us create a new Class class;
2. Write the Main method;
3. Let us create a new txt document in the root directory of drive C with the content 'test';
4. Then let us continue To write code, first create a File object;
5, and then create a StringBuilder object to store the read content;
6. Next, we use the BufferedReader class to read the content. Just write the code as shown;
7. Then we add the content Enter it into the console;
8. Then we run the program, and the console will print out the content of test;
Finish!
Recommended tutorial: java tutorial
The above is the detailed content of How to read data from file in java. For more information, please follow other related articles on the PHP Chinese website!