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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:28:00+00:00 2026-05-13T10:28:00+00:00

I am using jboss, eclipse and svn together. I have to files in my

  • 0

I am using jboss, eclipse and svn together. I have to files in my test folder: test/create.jsp and test/data.txt . What I want to do is when I call my create.jsp it will update my data.txt . Obviously I want my data.txt to stay where it is as other scripts are tryong to read from it.

I have tried dozens of new ways to put the path to my File object but for some reason it creates the file under jboss war folders.

Tried:

ServletContext app = getServletContext();
String path1 = app.getRealPath("/");
File f = new File(path1);
// AND
File f = new File("../../data.txt");
  • 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-13T10:28:00+00:00Added an answer on May 13, 2026 at 10:28 am

    Assuming that /test folder is located in the webcontent, then you need the following:

    String absolutePath = getServletContext().getRealPath("/test/data.txt");
    File file = new File(absolutePath);
    

    or

    String webcontentRoot = getServletContext().getRealPath("/");
    File file = new File(webcontentRoot, "test/data.txt");
    

    Do you see it? The Java IO only understands local disk file system paths, not URL’s or paths outside the context. The ServletContext#getRealPath() is to be used to convert a relative web path to an absolute local disk file system path which in turn can be used further in the usual Java IO stuff. You should never use relative paths in Java IO stuff. You will be dependent on the current working directory which may differ per environment/situation.

    That said, you normally don’t want to write files to the webcontent. They will get lost whenever you redeploy the WAR. Rather create a fixed disk file system path somewhere else outside the webapp and make use of it. Or even better, make use of an independent SQL database 🙂

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

Sidebar

Related Questions

I'm using Eclipse Juno and want to test my Java web app in JBoss
I am using Eclipse 3.7.2 with JBoss Tools 3.3 under Ubuntu 12 and have
I am using Eclipse 3.7 and I added JBoss as 7.1 server. I want
I am using Eclipse Helios and JBoss 4.2.0. I have built a maven project
I have created a EJB2.0 using Eclipse 3.7 IDE, and deployed it in JBoss
I'm using JBoss AS 7.1 and Hibernate in Eclipse 3.7.2 to build a Dynamic
I generated a web-service client using JBoss utils (JAX-WS compatible) using Eclipse 'web service
I'm working on a medium-size project using JBoss Developer Studio (based on Eclipse ).
Hi I'm using Eclipse on a EJB3 project, struts2 and hibernate.Server is JBoss 7.1.
I am using the latest Eclipse for Java EE & the latest JBoss Tools

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.