'Which OutputStream subclass to write to a text file

[Assignment]

Requirement

Use specifically OutputStream subclasses to output data to a .txt file, that can be read by a person using a program like Notepad. (so a Writer is not an option)

Thoughts

May be ASCII or any human-readable character set.

Question

Which one of these do I use?

  • ByteArrayOutputStream
  • FileOutputStream
  • FilterOutputStream
  • ObjectOutputStream
  • OutputStream
  • PipedOutputStream


Solution 1:[1]

Use a PrintStream. It is a subclass of OutputStream and allows for line-by-line output. It is the same class used in System.out

new PrintStream(new File("path/to/your/file.txt")).println("Your output");

Solution 2:[2]

Anything wrong with FileOutputStream?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xthexder
Solution 2 Bohemian