package sucai17;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Yewu {
public static void main(String[] args) throws Exception, IOException {
String encoding = "UTF-8";
File file = new File("C:\\Users\\admin\\Desktop\\1.txt");
if (file.isFile() && file.exists()) { //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
System.out.println(lineTxt);
}
read.close();
} else {
System.out.println("找不到指定的文件");
}
}
}
JAVA 读取本地文本文件
最新推荐文章于 2024-08-23 02:08:03 发布