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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:38:49+00:00 2026-06-15T09:38:49+00:00

I am trying to read a file in Java called KFormLList.txt. It is saved

  • 0

I am trying to read a file in Java called “KFormLList.txt”. It is saved in the default package along with this program, yet when I try to run it I get this error message: “Error: KFormLList.txt (The system cannot find the file specified)”

What am I doing wrong? Thanks for any help.

import java.io.*;

public class VLOCGenerater {

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        //Read the text file "KFormLList.txt"
        FileInputStream fis = new FileInputStream("KFormLList.txt");

        DataInputStream dis = new DataInputStream(fis);
        BufferedReader br = new BufferedReader(new InputStreamReader(dis));
        String strLine;
        int V = 0;
        int LOC = 0;

        while((strLine = br.readLine())!= null ){
            if (strLine.trim().length() != 0){
                System.out.println(strLine);
                V++;
                }
            else {
                LOC++;
            }
        }
        System.out.println("V = " + V);
        System.out.println("LOC = " + LOC);
        dis.close();
     }
     catch (Exception e){
     System.err.println("Error: " + e.getMessage());
    }

}

}
  • 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-15T09:38:52+00:00Added an answer on June 15, 2026 at 9:38 am

    Try putting the text file in the root directory of your project.

    The name parameter passed into the FileInputStream constructor is the path name to the file in the file system.

    A pathname, whether abstract or in string form, may be either absolute
    or relative. An absolute pathname is complete in that no other
    information is required in order to locate the file that it denotes. A
    relative pathname, in contrast, must be interpreted in terms of
    information taken from some other pathname. By default the classes in
    the java.io package always resolve relative pathnames against the
    current user directory. This directory is named by the system property
    user.dir, and is typically the directory in which the Java virtual
    machine was invoked.

    I assumed you were using Eclipse, by default Eclipse sets the user.dir to your the root of your project. From reading other material, Netbeans follows the same convention.

    This can be tested with the following code, which should output the path to your project:

    System.out.println(System.getProperty("user.dir"));
    

    Placing the file in the root of your directory allows it to be found by the FileInputStream.

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

Sidebar

Related Questions

i am trying to read an excel file using java. while compiling the program
I am trying to read file headers using java, I want to get file
I am trying to read a file and the error i get is java.io.FileNotFoundException:
I am trying to read a wav file from the resources of my Java
I'm just trying to do a simple text file read in java for my
I am trying to save a file (and then read it later) in java
I'm trying to read a file in my maven project at /src/main/resources/file.txt. I'm using
I am trying to read a file(temp.txt) placed under /root directory on remote host(ubuntu)
I'm facing this strange problem. I'm trying to read a file that is located
I'm trying to read a .java file into a JTextArea and no matter what

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.