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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:11:18+00:00 2026-06-06T11:11:18+00:00

I want to create an ouputStreamWriter object say out, for a file named say

  • 0

I want to create an ouputStreamWriter object say “out”, for a file named say “f”. I want this this file f to be created in a directory or folder named “output”. If the directory “output” does not exist then it should create it and if that already exists then it should create file “f” in that directory.

In short I want to have directory named “output” and then I want to put different files in it during execution of my program.

Could anyone please tell me how to do this in java ? Right now my following code is creating different files in current directoy. I want to put all files in a folder for my convinience.

public Dump(String outputFile) throws IOException {
        final FileOutputStream fos = new FileOutputStream(outputFile + "gz.xml");
        final GZIPOutputStream gzfos = new GZIPOutputStream(fos);
        out = new OutputStreamWriter(new BufferedOutputStream(gzfos), "UTF-8");

    }
  • 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-06T11:11:21+00:00Added an answer on June 6, 2026 at 11:11 am

    Hi There you can use the exists method on file to check if your directory/file exists all ready,

    File myOutputDir = new File("path");
    
    if(!myOutputDir.exists())
         myOutputDir.mkdir(); //Returns a boolean if you want to check it was successful.
    //Continue with your code the directory should now exist if it did not before.
    

    Cheers,

    E

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

Sidebar

Related Questions

I want create a pdf using iText. The method which does this is a
I want create object from Canvas3D class(in java) but my Compiler doesn't have this
I want create arrays with object keys in PHP, i.e. something like this: <?php
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want create module which update list of usb devices automatically (not only mass
I created a file and add some contents into it. Then, I want to
In C# code, I want create a log file for each each method in
I want create a tarball that when extracted the file(s) will be placed at
How to create a TIFF file in PHP? I want create a TIFF file
I want create a new JavaScript object based on an existing JavaScript object. Till

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.