Import the textfile and read it line by line in Java

I want to know how to import a text file I want to import a file and read it line by line

thank you!

Solution

I don't know what "import" file means, but it's the easiest way to open and read a text file line by line using standard Java classes (this should apply to all versions of Java Se and return JDK1.1. Using scanner is another option for JDK1.5 and later.)

BufferedReader br = new BufferedReader(
        new InputStreamReader(new FileInputStream(fileName)));
try {
    String line;
    while ((line = br.readLine()) != null) {
        // process line
    }
} finally {
    br.close();
}
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
分享
二维码
< <上一篇
下一篇>>