Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] FileReader/FileWriter 未关闭 / 没有正确关闭 #6

Open
Ghost-chu opened this issue Feb 21, 2022 · 0 comments
Open

[BUG] FileReader/FileWriter 未关闭 / 没有正确关闭 #6

Ghost-chu opened this issue Feb 21, 2022 · 0 comments

Comments

@Ghost-chu
Copy link

FileReader 打开后未关闭:

var ecoreData = gson.fromJson(new FileReader(economyCoreInternalDataFile), EcoreDataInternal.class);

FileWrite 关闭不正确:

var writer = new FileWriter(economyCoreInternalDataFile);
gson.toJson(ecoreData, writer);
writer.close();

使用 try-with-resources 来自动关闭。

try ( FileWriter writer = .... ) {
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant