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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:37:00+00:00 2026-05-15T16:37:00+00:00

I am trying to use Java’s Desktop / getDesktop() / open() call to open

  • 0

I am trying to use Java’s Desktop / getDesktop() / open() call to open a text (simple ASCII) file with the system’s default editor. I am using FileWriter / PrintWriter to write to the file, flush it, close it, but I get am getting an exception thrown.

  1. I am using the same File object in my desktop.open(savefile) as I am in my FileWriter fw = new FileWriter(savefile) call.

  2. I can open any other type of file with no problem, including other text files.

  3. If I suspend the program immediately after writing and replace the outputted file with a file created with a text editor, THEN select “open” on my dialog, it opens perfectly… it just seems my text files aren’t being created with the correct header or meta information that allows Desktop to know what to do with it.

Any assistance or experience would be appreciated. Is there an “official” file writer to use when simply dealing with text?

  • 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-15T16:37:01+00:00Added an answer on May 15, 2026 at 4:37 pm

    Sorry, can’t reproduce your issue here with this basic kickoff example:

    File file = new File("/test.txt");
    FileWriter writer = null;
    try {
        writer = new FileWriter(file);
        writer.write("test");
    } finally {
        if (writer != null) writer.close();
    }
    Desktop.getDesktop().open(file);
    

    Your problem lies somewhere else. Maybe you’re closing the wrong Writer handle (you should be closing the “outermost” writer, e.g. if you wrapped a FileWriter in a BufferedWriter, you should close BufferedWriter instead) or doing it too late (e.g. calling Desktop#open() inside try while you’re doing close in finally)?

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

Sidebar

Related Questions

I am trying to use Robot in Java to make an image file of
I'm trying to use java.util.List in a C# file. I have IKVM 0.40. I
I'm trying to use basic Java code in Scala to read from a file
I'm trying to use java to read a string from a file that was
I am trying to use Java's useDelimiter method on it's Scanner class to do
I am trying use a Java Uploader in a ROR app (for its ease
I am a complete JSP beginner. I am trying to use a java.util.List in
I'm trying to find the best way to use Java libraries that were installed
I'm trying to use checkstyle for a java project but I can't seem to
I'm trying to use this formula in JAVA : (-ln(1-L))/L I'm not sure how

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.