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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:38:25+00:00 2026-05-26T02:38:25+00:00

Im using java and jsf and I would like to create a folder within

  • 0

Im using java and jsf and I would like to create a folder within the server and then temporary save the files and delete it afterwards(not the folder itself).
I’ve tried this code:

boolean folderPath;
folderPath = new File ("/Images").mkdir();

but the code above created the folder in my local disk.

  • 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-26T02:38:26+00:00Added an answer on May 26, 2026 at 2:38 am

    Don’t do that. You can never guarantee that the WAR folder is writable or even on physical disk. For example, when the servletcontainer is configured to expand the WAR into memory instead of into disk.

    As it’s apparently a temporary file, rather just use File#createTempFile():

    File tempFile = File.createTempFile("filename", ".png");
    // ...
    

    Or use an external folder on the fixed disk file system whose absolute path is to be set as VM argument or some configuration setting.


    Update: you could use a servlet to display that file. I gather that it’s an image file. You can use <h:graphicImage> wherein you set the temp file’s filename in the path.

    E.g. inside the bean:

    this.filename = tempFile.getName();
    

    and then in the view:

    <h:graphicImage value="images/#{bean.filename}" />
    

    The servlet which should listen on /images/* can then just look like as follows (exceptional checks are omitted for your exercise):

    @WebServlet("/images/*")
    public class ImageServlet extends HttpServlet {
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            File file = new File(System.getProperty("java.io.tmpdir"), request.getPathInfo());
    
            response.setHeader("Content-Type", getServletContext().getMimeType(file.getName()));
            response.setHeader("Content-Length", String.valueOf(file.length()));
    
            InputStream input = new FileInputStream(file);
            OutputStream output = response.getOutputStream();
    
            // Now write input to output the usual way.
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JSF 2.0 with Facelets in a Java EE 6 application server (GlassFish
on my company we are developing a ERP-like app using java and jsf, so
I am using seam with EJB3 + JSF and I would like to add
how to render a datatable based on the list size in jsf using java
I'm building a Java Web Application using Java EE 6 and JSF-2.0, using the
I am building web app using Casssandra DB & Java with JSF 2.0 .
I'm developing a web application using JSF 2.0, NetBeans 6.9.1, GlassFish Server 3.1, mojarra
I'm developing a java EE web app using JSF with a shopping cart style
Setup: ICEfaces 1.8.2, Java EE 5, JSF 1.2. I'm using an ice:inputFile tag to
Using Java, how can I test that a URL is contactable, and returns a

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.