Posted In: IO, Java Core

How to create a temporary file/directory in Java

JDK 7 createTempDirectory and createTempFile method creates temp folder with given suffix. I have also added deleteOnExit to delete temp folder but dir.toFile().deleteOnExit() does not seem to be reliable on Windows. package com.example.java.core; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Test; public class TempFile { @Test public void create() throws Exception { Path dir = […]

Read More

by , on August 24th, 2017

Posted In: IO, Java Core

How to create a file and write text to it

Techniques used 1. Before JDK 7 using BufferedWriter 2. Using JDK 7 Files 3. Apache Commons IOUtils 4. Guava library  

Read More

by , on August 23rd, 2017

Posted In: IO, Java Core

How to create a Java List from the contents of a file

Techniques used 1. Before JDK 7 using BufferedReader 2. Using JDK 7 Files 3. Apache Commons IOUtils 4. Guava library  

Read More

by , on August 22nd, 2017

Posted In: IO, Java Core

How to create a Java string from the contents of a file

Techniques used 1. Before JDK 7 using BufferedReader 2. Using JDK 7 Files 3. Apache Commons IOUtils 4. Guava library  

Read More

by , on August 22nd, 2017

  • Categories