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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:20:57+00:00 2026-06-08T02:20:57+00:00

As the question states, I am trying to get a Path value, using JFileChooser.

  • 0

As the question states, I am trying to get a Path value, using JFileChooser. The returns from JFileChooser present me with two problems. First, the exact nature of what I am doing involves letting the user choose a directory, then, renaming all files of a certain type, for instance, all .pdf files, within that folder while leaving all other files alone. The problems I am having with JFileChooser in this regard are two-fold:

1) I have figured out how to let JFileChooser show the files inside a directory, but not allow the user to choose a file specifically. However, the return value of the string does not include the currently viewed directory inside JFileChooser when “Open” is pushed. For instance, if a user navigates to C:\Documents and Settings\myFolder\Documents\Work and sees the contents of the Work directory, then presses “Open”, the String returned as the getAbsolutePath() call is “C:\Documents and Setting\myFolder\Documents” the “Work” is never returned. How do I get that to be presented in the final outcome?

2) Once I have that String, how do I convert that to a Path so that I can operate on the files within it? The “\” is Java’s escape, and to use the file path as a valid Path value it needs to be escaped, i.e. “C:\Documents and Settings\myFolder” doesn’t work, it has to be “C:\Documents and Settings\myFolder”. How do I get from the single slash () return String from JFileChooser to the double slash (\) Path I need?

I know that the answer is likely simple, I am just more used to dealing with Linux, where this is not a problem. I have just landed my first job using my programming skills, and of course, everything is Windows.

And before someone suggests, yes, I know using “/” would work for relative paths, but for the application I am writing, I need to use absolute paths as these files could be on a host machine, or a network drive, so I can’t use relative naming, unless I am overlooking something due to not having a whole lot of network programming experience.

I thank you all for your time in reading, if not responding to this.

Tommie Matherne

  • 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-08T02:20:59+00:00Added an answer on June 8, 2026 at 2:20 am

    1. For getting the whole path of the selected directory do this:

    Here myJfc is an instance of JFileChoooser here

    String path =  myJfc.getSelectedFile().getAbsolutePath().toString();
    

    2. Conver the String into a path using this:

    Use “\\” instead of “\” in the path.

    ie. C:\\Documents and Settings\\myFolder

    Please see that you have proper Privilege in the C: drive else your file will not be created there, if you Do Not have the privilege to create a file in C: drive, try some other drive which you have like D:, E: etc.. You wont have any Privilege problem there.

    File f = new File(path);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get a value from a dropdown to fire a console.log('test') upon finding
So as the question states, im trying to create an array using a for
I'm trying to get a value from a netcat connection started at a php
as the question states, I am trying to get the avatars of each of
Okay so here is the deal. As the question states, I'm trying to POST
As the question states, I have two ethernet devices I need to use. A
As my question states, I can't figure out why, but while using WebMatrix to
I'm using Java 6. As the question states, how would I write a method
I am trying to get the powerstate for my windows mobile device. The states
I'm trying to iteratively traverse the United States in 1 mile increments using latitude

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.