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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:18:30+00:00 2026-05-13T22:18:30+00:00

I have recently created a web project in Java using eclipse. I have a

  • 0

I have recently created a web project in Java using eclipse. I have a servlet which includes a timer task. This timer tasks calls the “writeList” method of an XML Writing class that I have created. This all works fine, and I have verified that it runs every minute using System.out.

When I run my XML Writing class from within eclipse as an application, it works fine. The file is outputted to ‘WebContent/test.rdf’ without any problems.

However, when it is called by the timer task in my servlet, I am getting the following error:

java.io.FileNotFoundException: WebContent/Test.rdf(No such file or directory)
     at java.io.FileOutputStream.open(Native Method)
     at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
     at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
     at com.XMLWriter.writeList(XMLWriter.java:58)
     at com.ServerTimer$1.run(ServerTimer.java:30)
     at java.util.TimerThread.mainLoop(Timer.java:512)
     at java.util.TimerThread.run(Timer.java:462)

The code at line 58 of XMLWriter is as follows:

fileOut = new FileOutputStream("WebContent/TEST.rdf");
model.write(fileOut);

fileOut is a FileOutputStream, and model is an instance of a Jena model, as I am working with RDF.

Any help would be appreciated, I have been stuck with this for days now! Any questions just let me know!

EDIT: So it is working now, but I want to write the file to the ‘WebContent’ directory of my Web Project. Is there any way of doing this automatically? I can’t get the system to dynamically find that directory.

  • 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-13T22:18:30+00:00Added an answer on May 13, 2026 at 10:18 pm

    You should never rely on relative paths that way. Using relative paths in Java IO is asking for portability trouble. The java.io.File knows nothing about the web application context it is running in. The actual path would be dependent on the current working directory, which is not per se the same in all environments and depends on the way how you started the server/application. It may become relative to for example C:/Tomcat/bin and your TEST.rdf is obviously not there. Always use absolute paths, i.e. use the full disk file system path.

    In case of a JSP/Servlet webapplication you can use ServletContext#getRealPath() to convert a relative web path to an absolute disk file system path which you can use further in Java IO stuff. A relative web path is rooted in the public webcontent. Assuming that /TEST.rdf is located in the root of the public webcontent, then you can get an absolute disk file system path for /TEST.rdf inside a servlet the following way:

    String relativeWebPath = "/TEST.rdf";
    String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
    File file = new File(absoluteDiskPath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 339k
  • Answers 339k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming I understood the question properly: max_length = 10 #… May 14, 2026 at 4:29 am
  • Editorial Team
    Editorial Team added an answer Yes, it would be reasonable to have something which indicated… May 14, 2026 at 4:29 am
  • Editorial Team
    Editorial Team added an answer This works for me: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"… May 14, 2026 at 4:29 am

Related Questions

A hobby project of mine is a Java web application. It's a simple web
I've recently started playing around with ASP.NET and I was just about to connect
I've have been using Visual Studio 2005, alongside Visual Web Developer 2008 to create
I think back to Joel Spolsky's article about never rewriting code from scratch. To
A project I'm working on requires the use of jQuery on customers' Web pages.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.