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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:46:09+00:00 2026-06-14T08:46:09+00:00

I am writing a program that has multiple users, and I want each user

  • 0

I am writing a program that has multiple users, and I want each user to be able to save a file with a filename they choose, but, also append their username or a related key to the file name to help with searching later on. How can I adjust this code to do so?

For example, the user “bob” wants to save a file as “aFile.html”. The file I want to actually save would be “aFile_bob.html”

    String user = "bob";
    // select a file to save output
    JFileChooser JfileChooser = new JFileChooser(new File(defaultDirectory));
    JfileChooser.setSelectedFile(new File("TestFile.html"));
    int i = JfileChooser.showSaveDialog(null);
    if (i != JFileChooser.APPROVE_OPTION) return;
    File saveFile = JfileChooser.getSelectedFile();
    // somehow append "user" to saveFile name here?

    FileOutputStream fop = new FileOutputStream(saveFile);
  • 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-14T08:46:11+00:00Added an answer on June 14, 2026 at 8:46 am

    Use the renameTo method, like this:

    int lastDot = saveFile.getName().lastIndexOf('.');
    String name = saveFile.getName();
    String ext = ""; // Might not have a file extension
    if(lastDot > 0) { // At least one dot
        // Take substring of the last occurrence
        ext = saveFile.getName().substring(lastDot);
        name = name.substring(0, lastDot);
    }
    
    saveFile.renameTo(new File(defaultDirectory + "/" + name + "_" + user + ext));
    

    Using this method, you don’t need the FileOutputStream.

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

Sidebar

Related Questions

I'm writing a program that contains multiple packages in it. Each package has its
I'm writing a ruby program that has 2 threads. One that listens on an
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting
I'm writing a program that lets the user input 6 temperature readings, and then
I am writing a program that sets up a file path that I use
here Im writing a perl program which to parse a file, it contians multiple
I am writing a program that has to copy a sizeable, but not huge
I am writing a program that connects to a web host that has a
I'm writing a program that has to remove separator characters from quoted strings 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.