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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:54:19+00:00 2026-05-29T07:54:19+00:00

Hi Deployed the following code in eclipse //import cs1.Keyboard; import java.util.*; import java.io.*; public

  • 0

Hi Deployed the following code in eclipse

//import cs1.Keyboard;
import java.util.*;
import java.io.*;
public class Parser
{
    public static void main (String[] args) throws IOException
    {
        String [][] addyArray = new String[50][4];
        for (int j=0; j<50; j++)
        {
            for (int k=0; k<4; k++)
            {
                addyArray[j][k] = "\n";
            }
        }
        FileReader inFile = new FileReader ("sample.txt");
        BufferedReader in = new BufferedReader (inFile);
        String line = "";
        int i = 0, a = 0;
        while(in.ready())
        {
            line = in.readLine();
            while (line != null && line != "\n")
            {
                addyArray[i][a] = line;
                line = in.readLine();
                a++;
                if (line == null) line = "\n";
            }
            i++;
            a = 0;
        }
        for(int j=0; j<3; j++)
        {
            for(int k=0;k<4;k++)
            {
                System.out.println((j+1) + "-" + (k+1) + " " + addyArray[j] [k]);
            }
        }
    }
}

I am getting the following error at this line FileReader inFile = new FileReader ("sample.txt");

at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at Parser.main(Parser.java:19)

I placed sample.txt file in the same package folder where the above source code file was placed. I am not sure why I am getting this error. Can you please help me out. Thank you

  • 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-05-29T07:54:23+00:00Added an answer on May 29, 2026 at 7:54 am

    When you run a program in Eclipse, the current working directory, by default, is the root directory of your project. You probably have a sub-directory for your source code, so if you put “sample.txt” in it, it won’t be found.

    Either open the file as “<sub-directory>/sample.txt”, or (preferably) move the file to the root of your Eclipse project.

    Putting a file in your source code is only appropriate if it’s a “resource”; that is, some information that doesn’t need to be modified at runtime, but isn’t convenient to express as Java source code. For example, localized text and images for a UI is a resource, while a user-specified configuration for window sizes and positions is not. If a file is treated as a resource, you can load it with the getResourceAsStream() method of Class.

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

Sidebar

Related Questions

I have the following code. When deployed to a server, i m getting exception
I am new to servlet . I use the following code in servlet.then deployed
Context: MySQL server deployed with MysqldResource java class (Connector/MXJ lib). They app using mysql
I deployed a JAX-WS Service and use wsimport to generate client code. Because I
When I'm changing some Java source code and my server is running, hot deploy
I have a weird Chrome problem. I'm using the following code and style to
I have the following UDP broadcast listener running as a static component in a
I have a WAR file deployed to Tomcat server, one of the class will
We are using the following Apache Commons Net FTP code to connect to an
Following up this question here . I finally wrote up a code generation tool

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.