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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:17:36+00:00 2026-05-18T00:17:36+00:00

I referred to this example and created a servlet application. It works perfectly fine

  • 0

I referred to this example and created a servlet application.

It works perfectly fine with the TMP_DIR & DEST_DIR paths that is mentioned in the code(I have created a folder named tmp in C drive & also i have created a folder named files inside my application folder.

Now I am shifting the code to a linux machine, where this does not work since there is not drive named C: there. I tried replacing the c:\\tmp of the code to /tmp(and created a folder tmp) inside my application folder. But its not working. How can I make this code generic? Please advise.

  • 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-18T00:17:37+00:00Added an answer on May 18, 2026 at 12:17 am

    If what you want is a temporary directory use http://commons.apache.org/io/apidocs/org/apache/commons/io/FileUtils.html and look for getTempDirectory(). This should work anywhere

    So you need the System Temporary directory which is provided by the system. You can get this either through its path or through the actual File. (IOUtils provides both approaches). Here;s the IOUtil docs:
    getTempDirectory

    public static File getTempDirectory()
    
        Returns a File representing the system temporary directory.
    
        Returns:
            the system temporary directory.
    

    So if you write:

    File myTempFile = IOUtils.getTempDirectory();
    

    then myTempFile will be where you want to write to.

    If some app is asking for the directory by name then you can use getTempDirectoryPath()
    which will give the pathname.

    In your example I would write:

    private static final String TMP_DIR_PATH = IOUtils.getTempDirectoryPath();
    

    or using @dogbane’s approach:

    private static final String TMP_DIR_PATH = System.getProperty("java.io.tmpdir");
    

    I’d expect them to give the same answer.

    If you are still confused keep asking – that’s what SO is for!

    UPDATE: If you are doing anything with Files it’s worth becoming familiar with Apache’s FileUtils and IOUtils. There are several things that the JDK doesn’t do well or naturally and Apache gives better support.

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

Sidebar

Related Questions

I've already referred to this SO post . I've been embedding images using an
A while ago another question referred to the (possibly urban tale) statistic that ...
I am learning Servlets concept. Initially, I Tutorial referred to this link and working
Referred this question first. But seems my context is different. I'll try to be
Sometimes when I run my application it gives me an error that looks like:
I am not sure how this is referred to, but I am trying to
Well, this is the thing. Let's say that my future PHP CMS need to
C++ 0x has template aliases (sometimes referred to as template typedefs). See here .
I recently asked a question about what I called method calls. The answer referred
I'm using packages subfigure and float to create figures and tables that I want

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.