Skip to content

Avoid FileInputStream, FileOutputStream, FileReader and FileWriter #182

Closed
@jorsol

Description

@jorsol

The FileInputStream and FileOutputStream classes contains a finalizer method which will cause garbage collection pauses.

The FileReader and FileWriter constructors instantiate FileInputStream and FileOutputStream, again causing garbage collection issues while finalizer methods are called.

  • Use Files.newInputStream(Paths.get(fileName)) instead of new FileInputStream(fileName).
  • Use Files.newOutputStream(Paths.get(fileName)) instead of new FileOutputStream(fileName).
  • Use Files.newBufferedReader(Paths.get(fileName)) instead of new FileReader(fileName).
  • Use Files.newBufferedWriter(Paths.get(fileName)) instead of new FileWriter(fileName).

Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions