A simple implementation method of reading files in Java

This example describes a simple implementation method of reading files in Java, which is very practical. Share with you for your reference. The specific methods are as follows:

This is a simple code to read the file, and try to read a log file and then output it.

The main codes are as follows:

The output results are as follows:

Olympic refueling!

Come on, Beijing!

Go China!

Here, the FileReader class opens a file, but it does not know how to read a file. Therefore, the BufferedReader class needs to provide the function of reading text lines. This requires the combination of the functions of these two classes to achieve the purpose of opening and reading files. This is a technique for wrapping flow objects, that is, adding the services of one flow to another flow.

In addition, it should be noted that when Java opens a file according to the path, "/" and "/" are recognized, but when "/" is used, another "/" should be used to escape.

I hope this article will help you learn java programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>