Java creating file with Google Guava

In this example, we create a new file with Google Guava library.
For the project we need the guava dependency:
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.4-jre</version>
</dependency>
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;

public class JavaCreateFileExample {    
    public static void main(String[] args) throws IOException {
        
        Files.touch(new File("src/main/resources/myfile.txt"));
    }
}
The new file is created with Files.touch(). It accepts a File as a parameter.

Comments