Java — Create Temp File or Directory | Code Factory

Java Create Temp File example

package com.example.java.programming.file;import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* @author code.factory
*
*/
public class CreateTempFileExample {
public static void main(String... args) {
try {
Path tempFilePath = Files.createTempFile("test", ".txt");
System.out.printf("Temp file created at %s%n", tempFilePath);
} catch (IOException ex) {
System.out.format("I/O error: %s%n", ex);
}
}
}

Java Create Temp Directory example

package com.example.java.programming.file;import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* @author code.factory
*
*/
public class CreateTempDirectoryExample {
public static void main(String... args) {
try {
Path tempDirPath = Files.createTempDirectory("tempDir");
System.out.printf("Temporary folder created at %s%n", tempDirPath);
} catch (IOException ex) {
System.out.format("I/O error: %s%n", ex);
}
}
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Significance of Building Offline-First Apps : Aalpha

Reusable Modularity

How to monitor packet flow using the TCPDUMP

The beauty of a static library

Reminder to a Teams Channel Using Power Automate Flow

Do you want to learn to program with Flutter? Get ready!

Memory library in Kernel

Premium Product: Cloud Functions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

How to: Log4J2 and Graylog in a Spring Boot application

What is Lambda Expression in java? How to Use it?

From JAVA 9 to JAVA 15: Evolutions and new features — Part 1

SOLID Principles (Journey for writing readable and maintainable code)