package com.xiaoshi.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class ReadFiles {
public static void main(String[] args) {
File file = new File("c:/111.txt");
if (file.isFile() && file.exists()) {
try {
InputStream stream = new FileInputStream(file);
InputStreamReader read = new InputStreamReader(stream);
BufferedReader bfReader = new BufferedReader(read);
String a = null;
while ((a = bfReader.readLine()) != null) {
System.out.println(a);
}
bfReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
else {
System.out.println("文件不存在");
}
}
}
java读取本地txt文件
最新推荐文章于 2021-06-19 16:46:52 发布