我想知道如何读取内部存储器中某些文件的值,但这些文件不在“/data/data/myapp/files”文件夹中,它们位于“/dev/”和“/”文件夹中sys/class”文件夹。
import...
public class Calentando extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN );
setContentView( R.layout.activity_calentando );
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private byte[] readFile(String path) {
File file = new File( "/sys/class/gpio/gpio33/value" );
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 );
TextView Tempview = (TextView) findViewById( R.id.temperatura );
Tempview.setText( new String( readFile( path ), Charset.forName( "UTF-8" ) ) );
}
return baos.toByteArray();
} catch (IOException e) {
// handle the exception
return null;
}
}
}
森林海
GCT1015
随时随地看视频慕课网APP
相关分类