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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:04:28+00:00 2026-06-08T13:04:28+00:00

I have a project that finds a text file and makes it into an

  • 0

I have a project that finds a text file and makes it into an array of characters. However, for some reason or another it isn’t finding the file. This is all the code involving opening/reading the file:

public void initialize(){
    try{
    File file = new File(getClass().getResource("/worlds/world1.txt").toString());
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(
                new FileInputStream(file),
                Charset.forName("UTF-8")));
    int c;
    for(int i = 0; (c = reader.read()) != -1; i ++) {
      for(int x = 0; x < 20; x++){
          worlds[1][x][i] = (char) c;
          c = reader.read();
      }
    }
    }catch(IOException e){
        e.printStackTrace();
    }

}

When ran, it shows in the console that it is pointing to the correct file, but claims nothing exists there. I’ve checked, and the file is completely intact and in existence. What could be going wrong 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-08T13:04:30+00:00Added an answer on June 8, 2026 at 1:04 pm

    You should not get a resource like that. You can use

    BufferedReader reader = new BufferedReader(new InputStreamReader(
        getClass().getResourceAsStream("/worlds/world1.txt")
    ));
    

    Also, be careful when you package your application if you develop it inside an IDE, otherwise you’ll run into common CLASSPATH troubles

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

Sidebar

Related Questions

I have a project that I have divided quite aggressively into different layers. I
I have a project that using some third-party libraries. My questions is how to
I have a project that is displaying 16px text font at 0.5ems links on
I have got this project that uses excel for some calculation. This excel is
I have a personal project I'm working on that requires Microsoft SAPI5 -- text
I have two projects, my main android application and another test project that runs
I have a Visual Studio 2008 project that produces a file called: Game-Release.exe .
I have a problem with printing PDF file from a Java project that is
I have a project that includes 49 folders, each one has a file called
I have a text file that is automatically generated by an older computer system

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.