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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:31:03+00:00 2026-06-18T09:31:03+00:00

I am writing a small app that reads a csv file and displays the

  • 0

I am writing a small app that reads a csv file and displays the contents into a JList.

My current problem is that the new FileReader(file) code keeps giving me a java.io.FileNotFoundException error and I am not too sure why.

loadFile.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent actionEvent)
            {
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setCurrentDirectory(new File("~/"));

                if (fileChooser.showOpenDialog(instance) == JFileChooser.APPROVE_OPTION)
                {
                    File file = fileChooser.getSelectedFile();
                    CSVReader reader = new CSVReader(new FileReader(file.getAbsolutePath()));
                    fileLocation.setText(file.getAbsolutePath());

                }
            }
        });
  • 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-18T09:31:05+00:00Added an answer on June 18, 2026 at 9:31 am
    new File("~/")
    

    ~ is a Shell shortcut for the home directory. Use an absolute path like

    new File("/home/myself/")
    

    As pointed out by @pickypg, JFileChooser.setCurrentDirectory() sets the user’s home directory as default if the passed directory is invalid. So, even though File() does not interpret ~ as a Shell does, the JFileChooser starts in the user’s home directory – but this is true for any non-existing directory, for instance

    new File("/Windows")   // JFileChooser would start in "\Windows"
    new File("/xWindows")   // JFileChooser would start in the user's home directory
    

    As the documentation states, the user’s home directory is system specific, but on MS Windows it is typically the “My Documents” folder.

    But, even when using such an non-existing path as “~/”, JFileChooser.getSelectedFile() returns a proper path, so that FileReader() should not throw a FileNotFoundException.


    Based on the comments, it turns out that the issue is not a runtime exception, but a compile time error where the exception is not catched. Add a try{}catch{} block around your FileReader() constructor:

    try {
        CSVReader reader = new CSVReader(new FileReader(file.getAbsolutePath()));
    }catch(FileNotFoundException fnfe) {
        // handle exception, e.g. show error message
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking into writing a small custom app for a small business that can
I'm writing a small app that reads some input and do something based on
I am doing a file server migration and I'm writing a small C# app
I have a problem with a small app i am writing. Now either my
I'm writing a small app that will be the endpoint for NLog Network targets
I am writing a small app that uses the GAE. I have parts of
I'm currently writing a small python app that embeds cherrypy and django using py2app.
I'm writing a small Java app using JavaMail that sends the user an automated
I'm currently writing a small app that takes data provided by an SQL stored
I'm writing a small android app that lets the user pick a date and

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.