File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
main/java/org/apache/commons/io
test/java/org/apache/commons/io Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -2817,7 +2817,7 @@ public static List<String> readLines(final File file) throws IOException {
28172817 * @since 2.3
28182818 */
28192819 public static List <String > readLines (final File file , final Charset charset ) throws IOException {
2820- return Files .readAllLines (file .toPath (), charset );
2820+ return Files .readAllLines (file .toPath (), Charsets . toCharset ( charset ) );
28212821 }
28222822
28232823 /**
Original file line number Diff line number Diff line change @@ -2839,6 +2839,25 @@ public void testReadLines_Errors() {
28392839 assertThrows (UnsupportedCharsetException .class , () -> FileUtils .readLines (tempDirFile , "unsupported-charset" ));
28402840 }
28412841
2842+ @ Test
2843+ public void testReadLines_Defaults () throws Exception {
2844+ final File file = TestUtils .newFile (tempDirFile , "lines.txt" );
2845+ try {
2846+ final String [] data = {"hello" , "this is" , "some text" };
2847+ TestUtils .createLineFileUtf8 (file , data );
2848+
2849+ final List <String > lines1 = FileUtils .readLines (file );
2850+ final List <String > lines2 = FileUtils .readLines (file , (Charset ) null );
2851+ final List <String > lines3 = FileUtils .readLines (file , Charset .defaultCharset ());
2852+
2853+ assertEquals (lines1 , Arrays .asList (data ));
2854+ assertEquals (lines1 , lines2 );
2855+ assertEquals (lines1 , lines3 );
2856+ } finally {
2857+ TestUtils .deleteFile (file );
2858+ }
2859+ }
2860+
28422861 @ Test
28432862 @ EnabledIf ("isPosixFilePermissionsSupported" )
28442863 public void testReadLines_IOExceptionOnPosixFileSystem () throws Exception {
You can’t perform that action at this time.
0 commit comments