1 回答

TA貢獻1827條經驗 獲得超4個贊
由于您的應用程序具有 root 權限,您可能能夠訪問/dev和/sys/class目錄。
您可以列出目錄內容:
new File(path).listFiles();
您可以讀取二進制文件內容:
private byte[] readFile(String path) {
File file = new File(path);
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis)) {
byte[] buffer = new byte[4096];
int bytesRead;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((bytesRead = bis.read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
return baos.toByteArray();
} catch (IOException e) {
// handle the exception
return null;
}
}
您可以在 a 中設置文件內容TextView(前提是它是文本文件):
TextView Tempview;
Tempview = (TextView) findViewById( R.id.temperatura );
Tempview.setText(new String(readFile(path), Charset.forName("UTF-8")));
添加回答
舉報