其实就是用java的IO流去读取文件
public static String ReadTxtFile(String strFilePath) {
String path = strFilePath;
String gpioValue = "";
//打开文件
File file = new File(path);
//如果path是传递过来的参数,可以做一个非目录的判断
if (file.isDirectory()) {
Log.d(TAG, "这个目录不存在");
} else {
try {
InputStream instream = new FileInputStream(file);
if (instream != null)
{
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
//分行读取
while ((line = buffreader.readLine()) != null) {
gpioValue = line;
}
Log.i("gpioValue-----------", gpioValue + "==============");
instream.close();
}
} catch (java.io.FileNotFoundException e) {
Log.d(TAG, "文件目录异常或不存在");
} catch (IOException e) {
Log.d(TAG, e.getMessage());
}
}
return gpioValue;
}