下面是我的代码,我有这个奇怪的警告:Resource leak: 'br' is never closed
。谁能帮我解决这个警告。我不希望我的应用程序在将来崩溃或导致任何问题。
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);