Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6776313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:00:46+00:00 2026-05-26T16:00:46+00:00

[Assignment] Requirement Use specifically OutputStream subclasses to output data to a .txt file, that

  • 0

[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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:00:47+00:00Added an answer on May 26, 2026 at 4:00 pm
    • The ByteArrayOutputStream is to write bytes to an in-memory byte[] variable.
    • The FileOutputStream is to write bytes to a File.
    • The FilterOutputStream is a common superclass for more specific output streams which manipulate the data beforehand, such as encryption/decryption, calculating checksum, character encoding, compressing (zipping), etcetera. It does by itself nothing special.
    • The ObjectOutputStream is to write fullworthy Java types and objects in a serialized form into a byte stream. It basically allows to convert complex Java objects to raw bytes and vice versa.
    • The OutputStream is just the common abstract class of those streams. You can’t construct it anyway. You can however declare against it.
    • The PipedOutputStream is intented to be able to write to another InputStream in a pipe so that the other side can read them from that InputStream.

    You want to write the data plain to a File, so the FileOutputStream is more than sufficient.

    try (OutputStream output = new FileOutputStream("/foo.txt")) {
        output.write(text.getBytes());
    }
    

    Note that String#getBytes() uses the platform default encoding to convert characters to bytes. If you’re using "special characters" which are not covered by at least ASCII, then you should always explicitly specify the charset using String#getBytes(charset). E.g.:

        output.write(text.getBytes(StandardCharsets.UTF_8));
    

    Unrelated to the concrete question, the normal practice, however, is to use a Writer to write character data.

    If you don’t care about character encoding, use FileWriter:

    try (Writer writer = new FileWriter("/foo.txt")) {
        writer.write(text);
    }
    

    It will use the platform default character encoding which will usually also support ASCII characters.

    If you care about character encoding, use OutputStreamWriter:

    try (Writer writer = new OutputStreamWriter(new FileOutputStream("/foo.txt"), StandardCharsets.UTF_8)) {
        // ...
    }
    

    It allows you for specifying the charset as 2nd argument while taking an OutputStream.

    See also:

    • Java Basic I/O tutorial
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment that has asked me to copy a file using buffered
I have a string property that has a maximum length requirement because the data
The assignment at my first year uni computing course says my program should read
For a school assignment I have to write x86 assembly code, except I can't
For a homework assignment I was given a Card class that has enumerated types
I'm implementing a simple game for an assignment that would ideally run both on
I have a large filesystem that I need to traverse for errors. Each file
I have a class assignment where I have to write a program that will
I'm aware that the hashtable's Add and assignment-via-indexer operations are different (i.e. the latter
My question is in reference to an assignment that I am working on. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.