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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:35:34+00:00 2026-05-16T21:35:34+00:00

Basically my problem is a that I need to copy an uploaded file (which

  • 0

Basically my problem is a that I need to copy an uploaded file (which is placed in a temporary folder on my server providers Tomcat ie. not a local Tomcat).

The code I’m using works when I deploy my project on my local machine but stops working when I deploy it live.
I’ve found out that it has something to with my permissions in java.policy.

What I need to find out is how do I get access to the folder in which Tomcat stores the temporary file using Java.

When reading catalina.out this is the clue that the log gives me.

/usr/local/tomcat/work/Catalina/project name here/context of project here/upload_490341a6_12b1d397355_76ce_00000001.tmp

I’m thinking somewhere along the lines (note: this is not an actual method 😛 )

ServletActionContext.getContext().getSuperHiddenTemporaryCatalog();

The code snippet at the bottom has one flaw.

sourceFile and targetFile points to the same directory at the moment.

I want the sourceFile path to be the temporary tomcat-folder.

Thanks in advance! 😀


public String saveImage(File file, String uploadedFileName) {

    String path = ServletActionContext.getServletContext().getRealPath("images");

    System.out.println(path);

    String fullFileName = path + "/" + uploadedFileName;

    System.out.println(fullFileName);

    boolean successful = false;

    try {

        File sourceFile = new File(fullFileName);

        File targetFile = new File(path + "/" + uploadedFileName);

        InputStream in = new FileInputStream(sourceFile);
        OutputStream out = new FileOutputStream(targetFile);

        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();


    } catch (Exception e) {

        successful = false;

        e.printStackTrace();

    }

    if (successful) {

        return "context of project/images/" + uploadedFileName;

    } else {

        return "";

    }

}
  • 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-16T21:35:35+00:00Added an answer on May 16, 2026 at 9:35 pm
    File tempDir = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
    

    should give you access to your temporary directory in Tomcat. It would be strange if you could not at least read files from there.

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

Sidebar

Related Questions

I've a problem with LINQ. Basically a third party database that I need to
Basically my problem is that I need to write a script that automatically creates
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
So basically, I've run into this problem enough times that it is seriously frustrating
I have a pretty simple problem. Basically I have an array called $list that
currently I'm attempting to basically implement and exact copy of Apples iMessage App. That
i have a website which is basically a omegle copy ( text version only
I basically have this program which fetches orders from a database. My problem is
I have some localization problems in my webpage. There are basically two problems (that
Basically my problem is with the page at http://wiki.diablocommunity.com/index.php?title=Tristram_Cathedral Please see the screen shots

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.