TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
TIOBE - Java Coding Standard

Rule:  Optimization10Checked automatically with code checker

Synopsis:Avoid using FileStream
Severity Level:5


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).