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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:04:01+00:00 2026-05-17T19:04:01+00:00

I am using Eclipse to create a Dynamic Web Project. My eclipse is in

  • 0

I am using Eclipse to create a Dynamic Web Project. My eclipse is in

/home/pc/eclipse

and My project is in /home/pc/workspace/MyWebProj

Now I placed the files in the above Project Directory. When I want to read any File from my code, It always searches the files in /home/pc/eclipse folder instead of /home/pc/workspace/MyWebProj, thus I am hardcoding the file path for time being.

Is there any configuration setting in Eclipse I am missing?

Please Suggest.

Thank You,
Tara Singh

  • 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-17T19:04:02+00:00Added an answer on May 17, 2026 at 7:04 pm

    I think what you need to do is read the file from the location of the javax.servlet.ServletContext of the Web Application. If you use getContextPath() you should get the working directory of the Web Application rather than the Java VM.

    You could also try loading any files using the getResource and getResourceAsStream methods from the same class.

    I was a little rushed when I wrote this so I will provide a little more info.

    The best approach is to use the getResourceAsStream method. this allows you to access files within your webapp.

    To get a file foo.txt from the root directory of the web application and print it to the response, you could do the following.

    public class TestServlet extends HttpServlet {
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws javax.servlet.ServletException, java.io.IOException
        {
            PrintWriter writer = response.getWriter();
    
            // foo.txt is at the root directory of the web app
            InputStream in = getServletContext().getResourceAsStream("/foo.txt");
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    
            String text;
            while ((text = reader.readLine()) != null) {
                writer.println(text);
            }
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using EClipse, First: I created a Dynamic Web Project and copied soem JAR files
I'm using Eclipse Ganymede to create a web application, but the project's currently just
I have created a web application using Jersey and Dynamic Web Project of Eclipse.
If I create a utility project and multiple dynamic web projects within Eclipse and
I am using Eclipse (J2EE Galileo) and have created a dynamic web project and
I made a Dynamic web project in Eclipse using tomcat 7 (and I used
I m doing a project using eclipse plugins in jave to create an ide
I am trying to create an android project using eclipse IDE,its created successfully but
I have recently just created Java project using Eclipse that requires 2 JAR files
Using eclipse 3.5, when I create a new maven project, m2eclipse automatically adds J2SE1.4

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.