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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:21:53+00:00 2026-06-01T19:21:53+00:00

I was wondering how to get java to save a text file named hello.txt

  • 0

I was wondering how to get java to save a text file named hello.txt to the desktop without writing

"C:\\Users\\Austin\\Desktop"

Any help would be great. so like:

FileWriter fileWriter = new FileWriter(fileName.getText(), true);

..and the fileName.getText() is just going to be the ‘hello’.

UPDATE:
i think that i would be able to use the jfilechooser, so would this work?

JFileChooser chooser = new JFileChooser();
chooser.setVisible(true);

would that work? and if so, how would i get it to save the file using the selection in there?
im a noob…. 🙁

  • 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-01T19:21:54+00:00Added an answer on June 1, 2026 at 7:21 pm
    import java.io.File;
    
    class FindDesktopOnWindows {
    
        public static void main(String[] args) throws Exception {
            if (System.getProperty("os.name").toLowerCase().indexOf("win")<0) {
                System.err.println("Sorry, Windows only!");
                System.exit(1);
            }
            File desktopDir = new File(System.getProperty("user.home"), "Desktop");
            System.out.println(desktopDir.getPath() + " " + desktopDir.exists());
    
            java.awt.Desktop.getDesktop().open(desktopDir);
        }
    }
    

    I forgot different Locales. Very fragile code (even for code that starts out OS specific). See my comment below re. OS X/JFileChooser.

    ..how the (System.getProperty("user.home"), "Desktop") works..

    Oracle helpfully provides docs for this kind of thing.

    See System.getProperty(String) &
    new File(String,String).


    I’ll cede to an expert (or a user) on this, but I don’t think OS X supports any application icons or document icons directly on the ..start screen, default look, whatever.. Probably better to offer the end user a JFileChooser pointing to user.home and ask them to save the document to the desktop (or wherever they feel like).

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

Sidebar

Related Questions

I was wondering if in Java I would get any odd behaviour if I
I'm really wondering what this code does: scala> import java.nio.file._ import java.nio.file._ scala> Files.copy(Paths.get(),
Wondering if there is any way to get the lambda expressions that result from
Just wondering if there is any way to get the NS records in C#.
I'm wondering if there any gotchas or something like this with plain java new
Is there a quick way in java to get the nest/recurse level? I'm writing
I was wondering how to correctly use the Location.distanceBetween method in Java to get
Hi is there any way in Java to get staticly generic class type I
I am new to java text parsing and I'm wondering what is the best
I was wondering if Java get's assembled and in my readings I found the

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.