From 34d2e20e56029b05f6da6b510f2ab9d87e7ebf10 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 15 Jul 2020 12:33:27 +0200 Subject: [PATCH 1/2] JAVA-2096 Update "Create File" article --- core-java-modules/core-java-io-2/README.md | 2 +- core-java-modules/core-java-io-3/README.md | 7 ++ core-java-modules/core-java-io-3/pom.xml | 86 +++++++++++++++++++ .../createfile/CreateFileUnitTest.java | 50 +++++++++++ core-java-modules/pom.xml | 1 + 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-io-3/README.md create mode 100644 core-java-modules/core-java-io-3/pom.xml create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java diff --git a/core-java-modules/core-java-io-2/README.md b/core-java-modules/core-java-io-2/README.md index 84cabc5992..b078a66a7a 100644 --- a/core-java-modules/core-java-io-2/README.md +++ b/core-java-modules/core-java-io-2/README.md @@ -13,4 +13,4 @@ This module contains articles about core Java input and output (IO) - [How to Copy a File with Java](https://www.baeldung.com/java-copy-file) - [Create a Directory in Java](https://www.baeldung.com/java-create-directory) - [Java IO vs NIO](https://www.baeldung.com/java-io-vs-nio) -- [[<-- Prev]](/core-java-modules/core-java-io) +- [[<-- Prev]](/core-java-modules/core-java-io)[[More -->]](/core-java-modules/core-java-io-3) diff --git a/core-java-modules/core-java-io-3/README.md b/core-java-modules/core-java-io-3/README.md new file mode 100644 index 0000000000..39752346d3 --- /dev/null +++ b/core-java-modules/core-java-io-3/README.md @@ -0,0 +1,7 @@ +## Core Java IO + +This module contains articles about core Java input and output (IO) + +### Relevant Articles: +- [Java – Create a File](https://www.baeldung.com/java-how-to-create-a-file) +- [[<-- Prev]](/core-java-modules/core-java-io-2) diff --git a/core-java-modules/core-java-io-3/pom.xml b/core-java-modules/core-java-io-3/pom.xml new file mode 100644 index 0000000000..cb341ca2ae --- /dev/null +++ b/core-java-modules/core-java-io-3/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + core-java-io-3 + 0.1.0-SNAPSHOT + core-java-io-3 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + + com.google.guava + guava + ${guava.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + log4j + log4j + ${log4j.version} + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + com.github.tomakehurst + wiremock + ${wiremock.version} + test + + + + + + core-java-io-3 + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + 3.6.1 + 3.0.0-M1 + 2.26.3 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java new file mode 100644 index 0000000000..f3cdb22f4d --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java @@ -0,0 +1,50 @@ +package com.baeldung.createfile; + +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CreateFileUnitTest { + + private final String FILE_NAME = "src/test/resources/fileToCreate.txt"; + + @AfterEach + @BeforeEach + public void cleanUpFiles() { + File targetFile = new File(FILE_NAME); + targetFile.delete(); + } + + @Test + public void givenUsingNio_whenCreatingFile_thenCorrect() throws IOException { + Path newFilePath = Paths.get(FILE_NAME); + Files.createFile(newFilePath); + } + + @Test + public void givenUsingFile_whenCreatingFile_thenCorrect() throws IOException { + File newFile = new File(FILE_NAME); + boolean success = newFile.createNewFile(); + assertTrue(success); + } + + @Test + public void givenUsingGuava_whenCreatingFile_thenCorrect() throws IOException { + com.google.common.io.Files.touch(new File(FILE_NAME)); + } + + @Test + public void givenUsingCommonsIo_whenCreatingFile_thenCorrect() throws IOException { + FileUtils.touch(new File(FILE_NAME)); + } + +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 03b15f60d6..589097cf48 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -72,6 +72,7 @@ core-java-io core-java-io-2 + core-java-io-3 core-java-io-apis core-java-io-conversions core-java-io-conversions-2 From 0b083391bb81bf49f72594e7c337bcc17fa1c6d3 Mon Sep 17 00:00:00 2001 From: mikr Date: Thu, 16 Jul 2020 10:45:06 +0200 Subject: [PATCH 2/2] JAVA-2096 Add dummy file to make sure the directory is versioned --- core-java-modules/core-java-io-3/src/test/resources/dummy.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 core-java-modules/core-java-io-3/src/test/resources/dummy.txt diff --git a/core-java-modules/core-java-io-3/src/test/resources/dummy.txt b/core-java-modules/core-java-io-3/src/test/resources/dummy.txt new file mode 100644 index 0000000000..e69de29bb2