Example usage for java.io File createTempFile

List of usage examples for java.io File createTempFile

Introduction

In this page you can find the example usage for java.io File createTempFile.

Prototype

public static File createTempFile(String prefix, String suffix, File directory) throws IOException 

Source Link

Document

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

Usage

From source file:demoapp.fileupload_app.FileUploadController.java

public void handler(Response response, Form form) throws Exception, FileUploadException, ParserException {
    response.setContentType("text/plain");
    response.out().println("Induction - File Upload Demo - Response");
    response.out().println("----------------------------------------");

    response.out().println("");
    response.out().println("");

    response.out().println("General info");
    response.out().println("------------");
    response.out().println("\tform parameters: " + form.getParamNames());

    response.out().println("");
    response.out().println("");

    response.out().println("About the string you entered");
    response.out().println("----------------------------");
    response.out().println("\tvalue: \"" + form.getString("test_string") + "\"");

    FileHandle uploadedFile = form.getFile("test_file");

    File dumpFile = null;/*w w w .j  a v  a  2  s .  c o m*/
    if (uploadedFile.getSize() > 0) {
        dumpFile = File.createTempFile("test-", "-" + (new File(uploadedFile.getOriginFilename())).getName(),
                new File("c:/temp"));

        uploadedFile.write(dumpFile);
    }

    response.out().println("");
    response.out().println("");
    response.out().println("About the file you uploaded");
    response.out().println("---------------------------");
    response.out().println("\tfile name   : " + uploadedFile.getOriginFilename());
    response.out().println("\tcontent type: " + uploadedFile.getContentType());
    response.out().println("\tsize        : " + uploadedFile.getSize());

    if (dumpFile != null) {
        response.out().println("contents of uploaded file written to: " + dumpFile.getCanonicalPath());
    }
}

From source file:controller.ImageCTMH.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession();
    String mamh = session.getAttribute("mamh").toString();
    session.removeAttribute("mamh");
    if (!ServletFileUpload.isMultipartContent(request)) {
        out.println("Nothing to upload");
        return;/*  w w  w .j  a  va  2  s  . c  o m*/
    }
    FileItemFactory itemfactory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(itemfactory);
    String a = "";
    try {
        List<FileItem> items = upload.parseRequest(request);
        for (FileItem item : items) {
            String myfolder = ("asset/Images") + "/";
            File uploadDir = new File(
                    "E:/Cng ngh phn m?m/? ?n/1996Shop/ShopOnline/web/asset/Images");
            File file = File.createTempFile("img", ".png", uploadDir);
            item.write(file);
            a = myfolder + file.getName();
            ct.setHinhAnh(a);
            ct.setMaMh(Long.parseLong(mamh));
            cTHinhAnhDAO.insert(ct);
            response.sendRedirect("CTSanPham.jsp?MaMH=" + mamh + "");
        }

    } catch (FileUploadException e) {
        out.println("upload fail");
    } catch (Exception ex) {

    }
}

From source file:it.polimi.diceH2020.launcher.utility.FileUtility.java

public @NotNull File provideTemporaryFile(@NotNull String prefix, @Nullable String suffix) throws IOException {
    File file = File.createTempFile(prefix, suffix, settings.getWorkingDirectory());
    policy.markForDeletion(file);/*from  w  w w  .ja  v a  2 s  .com*/
    return file;
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.fileManagement.FileUtility.java

public @NotNull File provideTemporaryFile(@NotNull String prefix, String suffix) throws IOException {
    File file = File.createTempFile(prefix, suffix, settings.getWorkingDirectory());
    policy.markForDeletion(file);//  w ww .  j  a v  a 2  s.  c o m
    return file;
}