TextView textid;
textid = findViewById(R.id.textid);
File file = new File("/storage/emulated/0/hey.txt");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while((line = br.readLine())!=null){
text.append(line);
text.append("\n");
}
Log.i("text", text);
textid.setText(text);
}
catch (Exception e) {
e.printStackTrace();
根据我的要求,我需要在代码本身中提及文件的路径。而且,这没有用,我也没有在日志中看到任何内容。我将如何实施?
首先在清单文件中提供存储权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
如果写
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
您需要这些以便获得手机的权限才能授予对该文件的访问权限。