我想知道如何读取内部存储器中某些文件的值,但是这些文件不位于“ / data / data / myapp / files”文件夹中,而是位于“ / dev /”内部和“ / sys / class”文件夹。
<button type="button" className={"clear"} onClick={this.clearLast}>Clear last image</button>
特别感谢@nandsito
答案 0 :(得分:0)
由于您的应用具有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;
}
}
您可以在TextView
(如果它是文本文件)中设置文件内容:
TextView Tempview;
Tempview = (TextView) findViewById( R.id.temperatura );
Tempview.setText(new String(readFile(path), Charset.forName("UTF-8")));