Commit f769ddd47068fb335ee2d3490a2492d0ab49a13a
1 parent
28eb5de7
* 로그파일 뷰어
파일인코딩 추가. ISO-8859-1 => UTF-8
Showing
2 changed files
with
9 additions
and
5 deletions
Show diff stats
src/main/java/com/batch/controller/JobController.java
@@ -47,8 +47,10 @@ public class JobController { | @@ -47,8 +47,10 @@ public class JobController { | ||
47 | String filePath = params.get("filePath"); | 47 | String filePath = params.get("filePath"); |
48 | int readCnt = Integer.parseInt(params.get("readCnt")); | 48 | int readCnt = Integer.parseInt(params.get("readCnt")); |
49 | 49 | ||
50 | - sb = FileUtil.readFileLastLines(filePath, readCnt); | ||
51 | - | 50 | + sb = FileUtil.readFileLastLines(filePath, readCnt, "ISO-8859-1", "UTF-8"); |
51 | + | ||
52 | + log.info("sb ==="); | ||
53 | + log.info(sb.toString()); | ||
52 | return sb; | 54 | return sb; |
53 | } | 55 | } |
54 | 56 |
src/main/java/com/batch/util/FileUtil.java
@@ -36,7 +36,7 @@ public class FileUtil { | @@ -36,7 +36,7 @@ public class FileUtil { | ||
36 | * @param lineCnt | 36 | * @param lineCnt |
37 | * @return | 37 | * @return |
38 | */ | 38 | */ |
39 | - public static StringBuffer readFileLastLines(String resourceName, int lineCnt) { | 39 | + public static StringBuffer readFileLastLines(String resourceName, int lineCnt, String fEnc, String toEnc) { |
40 | StringBuffer sb = new StringBuffer(); | 40 | StringBuffer sb = new StringBuffer(); |
41 | 41 | ||
42 | // lineCnt = 50; // test case | 42 | // lineCnt = 50; // test case |
@@ -66,8 +66,10 @@ public class FileUtil { | @@ -66,8 +66,10 @@ public class FileUtil { | ||
66 | sb.insert(0, c); | 66 | sb.insert(0, c); |
67 | } | 67 | } |
68 | 68 | ||
69 | - /*** TODO : 필요 시 파일 인코딩. utf-8 **/ | ||
70 | -// sb = new StringBuffer(new String((sb.toString()).getBytes("ISO-8859-1"), "UTF-8")); | 69 | + /*** 필요 시 파일 인코딩. utf-8 **/ |
70 | + if(fEnc != null && !fEnc.isBlank() && toEnc != null && !toEnc.isBlank()) { | ||
71 | + sb = new StringBuffer(new String((sb.toString()).getBytes(fEnc), toEnc)); | ||
72 | + } | ||
71 | 73 | ||
72 | } catch (Exception e) { | 74 | } catch (Exception e) { |
73 | // e.printStackTrace(); | 75 | // e.printStackTrace(); |