Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,8 @@ public static String readFile(File file, String encoding) throws IOException {
StringBuffer sb = new StringBuffer();
List<String> lines = readTextLines(file, encoding);

for (Iterator<String> it = lines.iterator(); ; ) {
for (Iterator<String> it = lines.iterator(); it.hasNext(); ) {
sb.append(it.next());
if (it.hasNext()) {
sb.append("");
} else {
break;
}
}

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,26 @@ public void testReadFileWithAbsolutePath() throws IOException {
assertEquals(text, string);
}

/**
* 빈 파일 읽기 테스트. 내용이 없는 파일은 빈 문자열을 반환해야 한다.
*/
@Test
public void testReadEmptyFile() throws IOException {
String emptyPath = tmppath + "/empty.txt";
EgovFileUtil.writeFile(emptyPath, "", "UTF-8");
assertEquals("", EgovFileUtil.readFile(new File(emptyPath), "UTF-8"));
}

/**
* 여러 줄 파일 읽기 테스트. 줄들이 종전과 동일하게 연결되어야 한다.
*/
@Test
public void testReadMultiLineFile() throws IOException {
String multiPath = tmppath + "/multiline.txt";
EgovFileUtil.writeFile(multiPath, "line1\nline2\nline3", "UTF-8");
assertEquals("line1line2line3", EgovFileUtil.readFile(new File(multiPath), "UTF-8"));
}

/**
* 파일 복사 테스트.
*/
Expand Down