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

  • SEARCH
  • Home
  • 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 6863171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:45:00+00:00 2026-05-27T02:45:00+00:00

My web application generates an XML file. I’m using a Struts2 stream result to

  • 0

My web application generates an XML file. I’m using a Struts2 stream result to manage the download, here’s the action in struts.xml:

<action name="generateXML" class="navigation.actions.GenerateXML">
    <result type="stream">
        <param name="contentType">text/xml</param>
        <param name="inputName">inputStream</param>
        <param name="bufferSize">1024</param>
    </result>
    ...
</action>

Here’s the part of the action class “GenerateXML” where the FileInputStream “inputStream” is created:

public String execute() {
    File xml = new File(filename);
    ...//fill the file with stuff
    try {
        setInputStream(new FileInputStream(xml));
    } finally {
        //inputStream.close();
        xml.delete();
    }
}

Deleting the file won’t work because the inputStream isn’t closed yet (That part is commented out). However, if i close it at this point the xml file downloaded by the user is empty since its stream was closed before struts generates the download.
Besides using a script that regularly deletes those temporary files on the server, is there a way to close “inputStream” AFTER struts has done its thing?

  • 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-27T02:45:01+00:00Added an answer on May 27, 2026 at 2:45 am

    There isn’t a delete on close input stream, but you can write your own. See is there an existing FileInputStream delete on close?.

    The idea is that you don’t pass a FileInputStream, but pass your ClosingFileInputStream, which overrides close and deletes the file when close is called. The close() will be called by struts:

    public String execute() {    
        File xml = new File(filename);
            ...//fill the file with stuff
            setInputStream(new ClosingFileInputStream(xml));   
        }
    

    See the linked question for more information.

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

Sidebar

Related Questions

I am currently using xml as a config file for my silverlight application. I
I have a C# web application which generates SVG code using RaphaelJS , which
I'm currently developing a web application using Struts2 framework. This application requires to dynamically
I am trying to package my web application into war file using Ant. When
All, I am using Java/Jersey 1.9 to create a web service that generates XML.
My web application generates pdf files and either e-mails or faxes them to our
As part of a web application users can upload files of data, which generates
I am using iText to generate PDF invoices for a J2EE web application and
I am working on a web application (using Grails) which will generate a gift
In my Parameters.xml file, I have a couple of parameters that use the Web

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.