Skip to content

Commit 57be700

Browse files
authored
Merge pull request eugenp#5271 from amit2103/BAEL-8977
[BAEL-8977] - Added junit to read file into string through IOUtils
2 parents 08234b5 + f7b41ba commit 57be700

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎core-java-io/src/test/java/com/baeldung/file/FileOperationsManualTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.file;
22

33
import org.apache.commons.io.FileUtils;
4+
import org.apache.commons.io.IOUtils;
45
import org.hamcrest.CoreMatchers;
56
import org.hamcrest.Matchers;
67
import org.junit.Test;
@@ -120,4 +121,14 @@ private String readFromInputStream(InputStream inputStream) throws IOException {
120121

121122
return resultStringBuilder.toString();
122123
}
124+
125+
@Test
126+
public void givenFileName_whenUsingIOUtils_thenFileData() throws IOException {
127+
String expectedData = "This is a content of the file";
128+
129+
FileInputStream fis = new FileInputStream("src/test/resources/fileToRead.txt");
130+
String data = IOUtils.toString(fis, "UTF-8");
131+
132+
assertEquals(expectedData, data.trim());
133+
}
123134
}

0 commit comments

Comments
 (0)