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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:11:38+00:00 2026-06-02T22:11:38+00:00

I’m making a program that uses text files. I need to make it so

  • 0

I’m making a program that uses text files. I need to make it so that the program can be run from a different computer using its jar file. The problem is that I can’t get it to find the right file path to the text files. I’ve tried using getResource(), but it’s still not working right. Here’s the code:

public class Params {

    public static void init() {

        hsChartSuited = new int[13][13];

        file = new File(Params.class.getResource("HandStrengthDataSuited.txt").getFile());

        try {
            Scanner input = new Scanner(file);
            for (int i = 0; i < hsChartSuited.length; i++) {
                for (int j = 0; j < hsChartSuited[i].length; j++) {
                    hsChartSuited[i][j] = Integer.parseInt(input.next()) - 20;
                }
            }
        } catch (FileNotFoundException e) {
            System.out.println("File not found");

        }
}

HandStrengthDataSuited.txt is a file that is in the src folder for my project. It’s also located outside of the folder, in the project’s main directory as well. I’ve tried printing the absolute file path, and this is what I get:

/Users/MyUsername/file:/Users/MyUsername/Documents/Homework_Soph_2012/Computer%20Science/HoldEm/dist/HoldEm.jar!/holdem/HandStrengthDataSuited.txt

The file path that I need to get is

/Users/MyUsername/Documents/Homework_Soph_2012/Computer%20Science/HoldEm/holdem/HandStrengthDataSuited.txt

Does anyone know what the problem is here?

  • 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-02T22:11:40+00:00Added an answer on June 2, 2026 at 10:11 pm

    If your files is in src folder,

    class Tools {
        public static InputStream getResourceAsStream(String resource)
            throws FileNotFoundException
             {
            String stripped = resource.startsWith("/") ? resource.substring(1) : resource;
            InputStream stream = null;
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            if (classLoader != null) {
              stream = classLoader.getResourceAsStream(stripped);
            }
            if (stream == null) {
              stream = Tools.class.getResourceAsStream(resource);
            }
            if (stream == null) {
              stream = Tools.class.getClassLoader().getResourceAsStream(stripped);
            }
            if (stream == null) {
              throw new FileNotFoundException("Resource not found: " + resource);
            }
            return stream;
        }
    }
    

    Use:

    reader = new BufferedReader(new InputStreamReader(getResourceAsStream("org/paulvargas/resources/file.txt"), "UTF-8"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.