Here you can find the source of createTempFile(final String name)
Parameter | Description |
---|---|
name | file name |
public static File createTempFile(final String name)
//package com.java2s; /*//from www . j a va 2 s .c o m * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * * Alfresco is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Alfresco is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Alfresco. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.nio.charset.Charset; public class Main { /** * Create temp file TODO .. support multiple mimetypes .. build files with * real size content * * @param name file name * @return {@link File} file */ public static File createTempFile(final String name) { try { // create file File file = File.createTempFile(name, ".txt"); // create writer OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8").newEncoder()); try { // place content in file writer.write("this is a sample test upload file"); } finally { // close writer writer.close(); } return file; } catch (Exception exception) { throw new RuntimeException("Unable to create test file."); } } }