Skip to content

Java creating file with Apache Commons IO

Ramesh Fadatare edited this page Jul 11, 2019 · 1 revision

This example creates a file with the Apache Commons IO library.

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.6</version>
</dependency>

For the project we need the commons-io dependency.

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;

public class JavaCreateFileExample {
    
    public static void main(String[] args) throws IOException {
        
        FileUtils.touch(new File("src/main/resources/myfile.txt"));
    }
}

The new file is created with FileUtils.touch() method.

Clone this wiki locally