How to create temp file in given folder

package JavaIOExample;

import java.io.File;
import java.io.IOException;

/*
 * Here we will learn to create temp file in given directory instead of default temp directory.
 */
public class CreateTempDirInGivenDir {

	public static void main(String args[]) throws IOException {

		File tempFile = null;

		File tempFileLoc = new File("D:\JBT\testing");
		/*
		 * Creates an empty file in the default temporary-file directory, using
		 * the given prefix and suffix to generate its name.
		 */
		tempFile = File.createTempFile("tempPre", "tempSuff", tempFileLoc);

		/*
		 * exists() method tests whether the file or directory denoted by this
		 * abstract pathname exists or not accordingly it will return TRUE /
		 * FALSE.
		 */
		if (tempFile.exists())
			System.out.println("Temp File successfully created");
		else
			System.out.println("Failed to create Temp File");
	}
}

 

By | 2012-09-21T19:33:42+00:00 September 21st, 2012|Code Base|0 Comments

About the Author:

Leave A Comment