//读取txt文件, 返回值永远不为null
//注意要有存储权限
public static String readFile(String path) {
String result;
try {
File file = new File(path);//先读取info.txt
if (!file.exists()) {
return “”;
}
int length = (int) file.length();
byte[] buff = new byte[length];
FileInputStream fileInput = new FileInputStream(file);
fileInput.read(buff);
result = new String(buff, “UTF-8”);
fileInput.close();
return result;
} catch (Exception e) {
e.printStackTrace();
showTip(“读取文件失败,请检查是否打开存储权限”);
logRed(“读取文件失败, 路径:” + path);
return “”;
}
}
Android studio 读取txt文件内容
最新推荐文章于 2024-08-11 03:48:56 发布