Home  >  Article  >  Java  >  How to read data from file in java

How to read data from file in java

王林
王林Original
2019-11-13 09:41:478376browse

How to read data from file in java

1. First, let us create a new Class class;

How to read data from file in java

2. Write the Main method;

How to read data from file in java

3. Let us create a new txt document in the root directory of drive C with the content 'test';

How to read data from file in java

4. Then let us continue To write code, first create a File object;

How to read data from file in java

5, and then create a StringBuilder object to store the read content;

How to read data from file in java

6. Next, we use the BufferedReader class to read the content. Just write the code as shown;

How to read data from file in java

7. Then we add the content Enter it into the console;

How to read data from file in java

8. Then we run the program, and the console will print out the content of test;

How to read data from file in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn