{"id":214,"date":"2014-07-22T02:12:39","date_gmt":"2014-07-22T11:12:39","guid":{"rendered":"http:\/\/blog.box.kr\/?p=214"},"modified":"2014-07-22T02:12:39","modified_gmt":"2014-07-22T11:12:39","slug":"utf-8-%ec%9d%b8%ec%bd%94%eb%94%a9%eb%90%9c-%ed%8c%8c%ec%9d%bc-%ec%9d%bd%ea%b3%a0-euc-kr-%eb%b3%80%ea%b2%bd-encoded-file-read","status":"publish","type":"post","link":"https:\/\/blog.box.kr\/?p=214","title":{"rendered":"UTF-8 \uc778\ucf54\ub529\ub41c \ud30c\uc77c \uc77d\uace0 EUC-KR \ubcc0\uacbd encoded file read"},"content":{"rendered":"<p style=\"color: #000033;\">package com.javawide.files;<\/p>\n<p style=\"color: #000033;\">import java.io.*;<\/p>\n<p style=\"color: #000033;\">public class UTF8Reader {<br \/>\npublic static void main(String[] args) {<br \/>\nUTF8Reader reader = new UTF8Reader();<br \/>\ntry {<br \/>\nString utf8String = reader.readFully(&#8220;C:\/utf8test.txt&#8221;);<br \/>\nSystem.out.println(utf8String);<br \/>\nSystem.out.println(<span style=\"color: #ff9000;\">new String(utf8String.getBytes(), &#8220;EUC-KR&#8221;)<\/span>);<br \/>\n} catch (Exception e) {<br \/>\ne.printStackTrace();<br \/>\n}<br \/>\n}<\/p>\n<p style=\"color: #000033;\">\u00a0public String readFully(String fileName) throws Exception {<br \/>\nFile f = new File(fileName);<br \/>\nif(!f.exists()) return &#8220;No File&#8221;;<br \/>\nFileInputStream fis = new FileInputStream(f);<br \/>\nInputStreamReader in = new InputStreamReader(fis,\u00a0<span style=\"color: #ff9000;\">&#8220;UTF-8&#8221;<\/span>);<br \/>\nStringBuffer buffer = new StringBuffer();<br \/>\nint readed = 0;<br \/>\nchar[] buf = new char[4096];<br \/>\nwhile(-1 != (readed = in.read(buf)))<br \/>\nbuffer.append(buf, 0, readed);<br \/>\nreturn buffer.toString();<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>package com.javawide.files; import java.io.*; public class UTF8Reader { public static void main(String[] args) { UTF8Reader reader = new UTF8Reader(); try { String utf8String = reader.readFully(&#8220;C:\/utf8test.txt&#8221;); System.out.println(utf8String); System.out.println(new String(utf8String.getBytes(), &#8220;EUC-KR&#8221;)); } catch (Exception e) { e.printStackTrace(); } } \u00a0public String readFully(String fileName) throws Exception { File f = new File(fileName); if(!f.exists()) return &#8220;No File&#8221;; FileInputStream fis = new FileInputStream(f); InputStreamReader in = new InputStreamReader(fis,\u00a0&#8220;UTF-8&#8221;); StringBuffer buffer = new StringBuffer(); int readed = 0; char[] buf = new char[4096]; while(-1 != (readed = in.read(buf))) buffer.append(buf, 0, readed); return buffer.toString(); } }<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"ngg_post_thumbnail":0,"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[15,7],"tags":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5q9Zn-3s","jetpack-related-posts":[{"id":154,"url":"https:\/\/blog.box.kr\/?p=154","url_meta":{"origin":214,"position":0},"title":"Reading a UTF-8 Encoded File","date":"2014-07-06","format":false,"excerpt":"public static String parseTemplate(String templatePath) { File aFile = new File(templatePath); InputStreamReader reader = null; String template; StringBuffer temp = new StringBuffer(); int counter = 0; try { FileInputStream inStream = new FileInputStream(aFile); reader = new InputStreamReader(inStream, \"utf8\"); BufferedReader inBuf = new BufferedReader(reader); while ((template=inBuf.readLine()) != null) { if(counter ==\u2026","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":156,"url":"https:\/\/blog.box.kr\/?p=156","url_meta":{"origin":214,"position":1},"title":"reading text file with utf-8 encoding using java","date":"2014-07-06","format":false,"excerpt":"CASE 1. PrintStream out =newPrintStream(System.out,true,\"UTF-8\"); out.println(str); CASE 2. import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;publicclass test {publicstaticvoid main(String[] args){try{File fileDir =newFile(\"PATH_TO_FILE\");BufferedReader in =newBufferedReader(newInputStreamReader(newFileInputStream(fileDir),\"UTF8\"));String str;while((str = in.readLine())!=null){System.out.println(str);} in.close();}catch(UnsupportedEncodingException e){System.out.println(e.getMessage());}catch(IOException e){System.out.println(e.getMessage());}catch(Exception e){System.out.println(e.getMessage());}} }","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":583,"url":"https:\/\/blog.box.kr\/?p=583","url_meta":{"origin":214,"position":2},"title":"java\ub85c unzip","date":"2015-01-28","format":false,"excerpt":"http:\/\/sourceforge.net\/projects\/jazzlib\/ \u00a0 Java comes with \u201cjava.util.zip\u201d library to perform data compression in ZIp format. The overall concept is quite straightforward. Read file with \u201cFileInputStream\u201d Add the file name to \u201cZipEntry\u201d and output it to \u201cZipOutputStream\u201c 1. Simple ZIP example Read a file \u201cC:\\spy.log\u201d and compress it into a zip file\u2026","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":212,"url":"https:\/\/blog.box.kr\/?p=212","url_meta":{"origin":214,"position":3},"title":"JAVA &#8211; \ud55c\uae00 \uc778\ucf54\ub529 \ubcc0\ud658 \uccb4\ud06c \ud55c\ubc29\uc5d0 \ub05d\ub0b4\uae30\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0","date":"2014-07-22","format":false,"excerpt":"String word = \"\ubb34\uad81\ud654 \uaf43\uc774 \ud53c\uc5c8\uc2b5\ub2c8\ub2e4.\"; System.out.println(\"utf-8 -> euc-kr\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \" + new String(word.getBytes(\"utf-8\"), \"euc-kr\")); System.out.println(\"utf-8 -> ksc5601\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \" + new String(word.getBytes(\"utf-8\"), \"ksc5601\")); System.out.println(\"utf-8 -> x-windows-949 : \" + new String(word.getBytes(\"utf-8\"), \"x-windows-949\")); System.out.println(\"utf-8 -> iso-8859-1\u00a0\u00a0\u00a0 : \" + new String(word.getBytes(\"utf-8\"), \"iso-8859-1\")); System.out.println(\"iso-8859-1 -> euc-kr\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : \" + new String(word.getBytes(\"iso-8859-1\"),\u2026","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":347,"url":"https:\/\/blog.box.kr\/?p=347","url_meta":{"origin":214,"position":4},"title":"java\uc5d0\uc11c string \uc778\ucf54\ub529 \ud655\uc778\ubc29\ubc95","date":"2014-08-17","format":false,"excerpt":"String word = s; System.out.println(\"utf-8(1) : \" + new String(word.getBytes(\"utf-8\"), \"euc-kr\")); System.out.println(\"utf-8(2) : \" + new String(word.getBytes(\"utf-8\"), \"ksc5601\")); System.out.println(\"utf-8(3) : \" + new String(word.getBytes(\"utf-8\"), \"x-windows-949\")); System.out.println(\"utf-8(4) : \" + new String(word.getBytes(\"utf-8\"), \"iso-8859-1\")); System.out.println(\"iso-8859-1(1) : \" + new String(word.getBytes(\"iso-8859-1\"), \"euc-kr\")); System.out.println(\"iso-8859-1(2) : \" + new String(word.getBytes(\"iso-8859-1\"), \"ksc5601\")); System.out.println(\"iso-8859-1(3) : \" +\u2026","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":208,"url":"https:\/\/blog.box.kr\/?p=208","url_meta":{"origin":214,"position":5},"title":"\uc790\ubc14 \ud1a0\ud070 \ud1a0\ud06c\ub098\uc774\uc838(StringTokenizer)\ub85c \ud30c\uc77c\uc785\ub825 \ud30c\uc77c\ucd9c\ub825","date":"2014-07-21","format":false,"excerpt":"import java.io.*; import java.util.*; public class A { \u00a0 public static void main(String[] args) throws IOException{ FileInputStream fin = new FileInputStream(\"a.txt\"); BufferedReader in =\u00a0 new BufferedReader((new InputStreamReader(fin, \"UTF-8\"))); BufferedWriter Bout =\u00a0 new BufferedWriter(new FileWriter(\"B.txt\")); BufferedWriter Cout =\u00a0 new BufferedWriter(new FileWriter(\"C.txt\")); \u00a0\u00a0\u00a0 String temp; int key = 0; while((temp = in.readLine())\u2026","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/214"}],"collection":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=214"}],"version-history":[{"count":0,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/214\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}