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 8755711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:54:29+00:00 2026-06-13T13:54:29+00:00

I create a text file with some headers and then close it, afterwards when

  • 0

I create a text file with some headers and then close it, afterwards when I have data that I wish to write to that file nothing happens,my code is below and the stack trace that I get when I try to print to it.

public class Writetofile {

    BufferedWriter writer = null;

    public void recordData(String record) throws IOException {

        try {
            writer.append(record);
            writer.newLine();
            writer.close();
        } catch (Exception e) {e.printStackTrace();
        }
    }

    public void createtxtfile(String[] details) throws IOException {
        String machine = details[0];
        String date = details[1];
        String start_time = details[2];
        try {
            File new_cal = new File("C:\\Activity_Calibrator\\log\\" + machine + "//" + machine + ".txt");
            new_cal.getParentFile().mkdirs();
            FileWriter fwriter = new FileWriter(new_cal);
            writer = new BufferedWriter(fwriter);
            writer.append("Linear Calibration for " + machine + " carried out " + date);
            writer.newLine();
            writer.close();
        } catch (Exception e) {
        }
    }
}

Message that is recieved
java.io.IOException: Stream closed
  at java.io.BufferedWriter.ensureOpen(BufferedWriter.java:116)
  at java.io.BufferedWriter.write(BufferedWriter.java:221)
  at java.io.Writer.write(Writer.java:157)
  at java.io.Writer.append(Writer.java:227)
  at Writetofile.recordData(Writetofile.java:27)
  at UserInterFace.update(UserInterFace.java:75)
  at Comms.serialEvent(Comms.java:124)
  at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
  at gnu.io.RXTXPort.eventLoop(Native Method)
  at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)

This is hard to understand as I have read that I should always close a Stream after writing to it.

  • 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-06-13T13:54:30+00:00Added an answer on June 13, 2026 at 1:54 pm

    nothing happens, and I do not get an error

    A good first step would be not to swallow exceptions – for example you could print the stack trace to the console:

    } catch (Exception e) {
        e.printStackTrace();
    }
    

    Then you will get a proper exception message which should help you find your issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Cross-post http://perlmonks.org/index.pl?node_id=979710 I'm trying to create a text file from some XML using Perl
I want to pre-append some text a a CSV file that is created by
If I create a text file on an operating system that uses the Latin
is it possible to create a text file on the fly and then ask
I need to create an ANSI text file from an Access recordset that outputs
I have a page in JSP that list some file that could be downloaded
I am trying to create a text file using VB.Net with UTF8 encoding, without
I'm looking for a way to (hopefully) create a text file which lists all
I want to be able to create a temporary text File in Java to
Can I create a Hive table from a sql/text file like we do in

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.