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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:37:57+00:00 2026-05-27T17:37:57+00:00

I have to read a file using servlet.here is the code iam using.but file

  • 0

I have to read a file using servlet.here is the code iam using.but file is not reading using this code.Always printing File contains null value-----------------:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        response.setContentType("text/html");
        String filename = "D/root.properties";
        ServletContext context = getServletContext();

        InputStream inp = context.getResourceAsStream(filename);
        if (inp != null) {
            InputStreamReader isr = new InputStreamReader(inp);
            BufferedReader reader = new BufferedReader(isr);
            PrintWriter pw = response.getWriter();

            String text = "";

            while ((text = reader.readLine()) != null) {                     
            }
        } else {
            System.out.println("File contains null value-----------------");
        }
    } catch(Exception e) {
        System.out.println("Rxpn............................................."+e);
    }
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
}
  • 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-27T17:37:58+00:00Added an answer on May 27, 2026 at 5:37 pm

    javadoc to the rescue :

    java.net.URL getResource(java.lang.String path)
    throws java.net.MalformedURLException

    Returns a URL to the resource that is mapped to the given path.

    The path must begin with a / and is interpreted as relative to the current context root, or relative to the /META-INF/resources directory
    of a JAR file inside the web application’s /WEB-INF/lib directory.
    This method will first search the document root of the web application
    for the requested resource, before searching any of the JAR files
    inside /WEB-INF/lib. The order in which the JAR files inside
    /WEB-INF/lib are searched is undefined.

    If you want to read from a resource in the web app, use a path as indicated above. If you want to read from the file system, use file IO (and the correct file name): new FileInputStream("D:/root.properties")

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

Sidebar

Related Questions

I have got the following code from here to read an Excel file using
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
I have read samples out of a wave file using the wave module, but
I have a file that I want to read in using the File::Slurp module
I have a config file that I read using the RawConfigParser in the standard
I have read a file into a String. The file contains various names, one
I have to read a txt file with lines formated like this: 1: (G,
I have a servlet that construct response to a media file request by reading
for my application i have to parse CSV file using Erlang.following is the code
I'm trying to read an Excel (xlsx) file using the code shown below. I

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.