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

MEDTRACK

IronHack Challenge 2: Wireframing

LOFI-DEFI: MOVING FORWARD!

Top C++ Compilers for Windows in 2020

My day at a Raspberry Jam

Shorter Supply Chains, Higher Expectations

Flutter Web and Flame

Flutter — How to replace the bundled Dart SDK in Flutter to Apple Silicon (ARM64) on Apple Silicon…

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

Decoding The JVM Architecture — Here’s How JVM Works

AWS SDK 1.x to 2.x migration and upgrade — learnings and takeaways

Access modifiers in java

Cloud Storage, Java