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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:59:25+00:00 2026-06-04T00:59:25+00:00

I have the following problem: I created the servlet which should draw a dynamic

  • 0

I have the following problem:

I created the servlet which should draw a dynamic graph. During the drawing process it should fetch the picture from another directory and to draw it upon another image. Everything should work fine:

try {
            BufferedImage temp = ImageIO.read(new File("image/arrow.png"));
            tempIm = temp.getScaledInstance(55, 55, Image.SCALE_SMOOTH);
        } catch (IOException e) {

            e.printStackTrace();

        }

But it prints the following:

SEVERE: javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1275)
at CertificateDraw.doGet(CertificateDraw.java:36)

I tried to change the path of the File object in all possible ways it just gives the same problem even though the part of the image is still sent to the browser. So the problem is with the ImageIO.read part – how can I find why it does not load the image?!

I am working in Eclipse – servlet is in the src folder. The image is in “image” folder under the rot directory “WebContent”.

  • 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-04T00:59:26+00:00Added an answer on June 4, 2026 at 12:59 am

    Relative paths in java.io.File are relative to the current working directory (CWD). This is the folder which is currently opened when the command is given to start the Java runtime environment (in your case, the webserver). When starting the server in Eclipse, this is usually the /bin folder of the project. You can figure this by printing new File(".").getAbsolutePath().

    But you shouldn’t be relying on relative paths in File at all. The CWD is not controllable from inside the code.

    As it’s in the webcontent folder already, just get it by ServletContext#getResourceAsStream() instead.

    InputStream input = getServletContext().getResourceAsStream("/image/arrow.png");
    BufferedImage image = ImageIO.read(input);
    // ...
    

    Note that the getServletContext() is inherited from the GenericServlet class which the HttpServlet extends from, so you don’t need to provide the method yourself.

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

Sidebar

Related Questions

Im facing following problem I have created mentioned condition, but when I choose y
I have defined the following ApplicationManifest file the problem is that i have created
I have the following problem in application express which is driving me crazy: I
I have a following problem. I have a ListView which returns data from SQL
I have the following problem: I have a Wintec WBT-202 GPS device which has
I have following problem. I have created a tab based Application with three Views
I'm not sure if this is possible, but have the following problem... Have created
I have the following problem: I created a iOS 5 SDK application with Storyboard
I have the following problem: I created content type movies and content type actors.
Hello I have following Problem: Within an uninstall-process I load a JAR (jdbc-driver). URL

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.