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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:24:44+00:00 2026-06-13T00:24:44+00:00

I am trying to read a file in a servlet. I am using eclipse

  • 0

I am trying to read a file in a servlet. I am using eclipse IDE.

I get a FileNotFoundException if I provide relative file name.

List<String> ls=new ArrayList<String>();
Scanner input = new Scanner(new File("Input.txt"));
while(input.hasNextLine()) {
   ls.add(input.nextLine());
}

The same code works if I put the absolute path like this:

Scanner input = new Scanner(new File("F:/Spring and other stuff/AjaxDemo/src/com/pdd/ajax/Input.txt"));

The Java file and text file are there in the same folder.

Does it searches text file in some other folder ?

  • 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-13T00:24:45+00:00Added an answer on June 13, 2026 at 12:24 am

    Setting the Working Directory

    One option you have when working inside of Eclipse is to set the working directory in your launch configuration. To do this:

    1. Navigate to Run | Run Configurations…
    2. Select your configuration in the left hand pane
    3. Select the Arguments tab
    4. Navigate to the Working directory section
    5. Select Other
    6. Enter in your desired base directory

    You can validate this in a test by printing:

    System.getProperty("user.dir") 
    

    This has the benefit of not changing your code for production vs. test.

    Recommendation

    However, the best approach is to always be explicit about the working directory by way of configuration. This puts the working directory under the direct control of your application and away from tools and servlet containers such as Eclipse and Tomcat. To do this, you would use the following File constructor

    new File(parent, file)
    
    • 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 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 file and split its line to get some context(Computer
I'm trying to read a file in my maven project at /src/main/resources/file.txt. I'm using
I'm trying to read a file line by line to a string type variable
I am trying to read a file using File Reader but I continue to
I'm working with Spring/Hibernet using NetBeans 6.9.1. I'm trying to read an Excel file
When trying to read a csv file in StatET/Eclipse (OS X 10.6, Eclipse 3.6)
I am trying to read an MS Project File using the .net version of
I'm trying to read a text file, i'm using fileImputStream, and reading all the

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.