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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:56:51+00:00 2026-06-01T12:56:51+00:00

I have a large-ish project that contains one class that reads from a file

  • 0

I have a large-ish project that contains one class that reads from a file (I have enclosed an SSCCE below). Everything works as it should. However, when I use either the Apple Jar Bundler or Eclipse’s “Export to Mac OS X Application command” (following these instructions), it doesn’t work, and I get a java.io.FileNotFoundException.

I am trying to find out why I get this FileNotFoundExceptionand how I can prevent it. My guess is that Eclipse is using its own classloader or something and that said classloader is not being properly invoked in the exported jar and hence the app.

SSCCE: The following code works when run from Eclipse, but not from a .app, java -jar, or even from the java readfromfile.ReadFromFile executed from the bin directory.

In ReadFromFile.java:

package readfromfile;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ReadFromFile {
    public static void main(String[] args) {
        String filepath = "src/readfromfile/file.txt";
        try {
            BufferedReader br = new BufferedReader(new FileReader(filepath));
            JFrame frame = new JFrame();
            frame.getContentPane().setLayout(
                    new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
            for (String line; (line = br.readLine()) != null;) {
                frame.getContentPane().add(new JLabel(line));
            }
            frame.pack();
            frame.setVisible(true);
        } catch (FileNotFoundException e) {
            System.err.println("File not found");
            e.printStackTrace();
        } catch (IOException e) {
            System.err.println("IOexception");
            e.printStackTrace();
        }
    }
}

In file.txt:

I am 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-06-01T12:56:52+00:00Added an answer on June 1, 2026 at 12:56 pm

    When you create the Jar Bundle maybe the src/... path does not exist.

    Why don’t you put the file as packages resource and you read it with:

    Reader r = new InputStreamReader(ReadFromFile.class.getResourceAsStream("file.txt"));
    BufferedReader br = new BufferedReader(r);
    

    Naturally you have to put the file “file.txt” in the same package of your class.

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

Sidebar

Related Questions

I have a large-ish PHP project (hundreds of files) that I've been brought in
I have a large-ish file (4-5 GB compressed) of small messages that I wish
I have a large-ish Visual Studio 2010 solution (~110 C# projects). One project (let's
We have a large-ish query here that has several params, and for each one,
I have a large-ish web project which is migrating from classic ASP to ASP.NET
I have a large(ish) COM object that works as the back end of my
For javascript functions that only apply to one page, in a large(ish) web app
I have several large projects that I work on. Depending on the project and
In SQL Server 2005, I have a query that involves a bunch of large-ish
I'm going to be starting a project soon that requires support for large-ish binary

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.