TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Create Temporary File In Java Program
Alagunila Meganathan
Aug 10
2016
Code
628
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
CreateTemporaryFile.
import
java.io.*;
public
class
CreateTemporaryFile{
CreateTemporaryFile(){
}
public
static
void
CreateTempFile(){
try
{
// Create a temporary file object
File tempFile = File.createTempFile(
"prefix"
,
"suffix"
);
System.out.println(
"\nTemporary file file has been created : "
+ tempFile +
"\n"
);
// Write to temporary file
BufferedWriter out =
new
BufferedWriter(
new
FileWriter(tempFile));
out.write(
"You are writing on temporary file which will delete on exit : "
+ tempFile);
out.close();
// Delete temp file when program exits
tempFile.deleteOnExit();
}
catch
(IOException e){
System.out.println(
"Exception is"
+ e);
}
}
public
static
void
main(String[] args){
CreateTempFile();
}
}
java
temporary file