Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

The resource was closed incorrectly #955

Open
QiAnXinCodeSafe opened this issue Jul 11, 2019 · 0 comments
Open

The resource was closed incorrectly #955

QiAnXinCodeSafe opened this issue Jul 11, 2019 · 0 comments

Comments

@QiAnXinCodeSafe
Copy link

The code may throw an exception before the resource is closed,you should use try-catch-finally or try-with-resource to close resource

OutputStream os = urlConnection.getOutputStream();
os.write(mJsonObject.toString().getBytes("UTF-8"));
os.close();

GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(src));
FileOutputStream out = new FileOutputStream(dest);
int len;
while ((len = gzis.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
gzis.close();
out.close();
} catch(IOException ex){

The resource is not closed
inputStream = new BufferedInputStream(urlConnection.getInputStream());
result = readInputStream(inputStream);
} catch (IOException e) {
ioException = e;
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant