Android资源泄漏尝试
下面是我的代码,我有一个奇怪的警告:Android资源泄漏尝试,android,Android,下面是我的代码,我有一个奇怪的警告:资源泄漏:“br”永远不会关闭。有人能帮我警告一下吗。我不希望我的应用程序在将来崩溃或引起任何问题 File sdcard = Environment.getExternalStorageDirectory(); File file = new File(sdcard,"/St/"+ textToPass); StringBuilder text = new StringBuilder(); try { BufferedReader br = new
资源泄漏:“br”永远不会关闭。有人能帮我警告一下吗。我不希望我的应用程序在将来崩溃或引起任何问题
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/St/"+ textToPass);
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');
}
}catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
TextView output=(TextView) findViewById(R.id.st);
// Assuming that 'output' is the id of your TextView
output.setText(text);
您没有关闭BufferedReader
BufferedReader.close()
将关闭两条流。以下是
他们建议使用br.close()
试试这个使用br.Close()关闭br。谢谢。算了吧。