Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android资源泄漏尝试_Android - Fatal编程技术网

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。谢谢。算了吧。