import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
//content用来存储读取到的信息
StringBuffer content = new StringBuffer();
//定义编码方式(我txt电脑写入的是GBK,不一定是网上说那四种)
String encoding = "UTF-8";
//path为文件所在路径
File file = new File(path);
//判断文件是否存在
if (file.isFile() && file.exists()) {
//文件存在,进行读取
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineText = null;
while ((lineText = bufferedReader.readLine()) != null) {
content.append(lineText);
}
read.close();
//需要的话将内容转换为String
String con=content.toString();
}