{"id":154,"date":"2014-07-06T20:09:39","date_gmt":"2014-07-07T05:09:39","guid":{"rendered":"http:\/\/blog.box.kr\/?p=154"},"modified":"2014-07-06T20:09:39","modified_gmt":"2014-07-07T05:09:39","slug":"reading-a-utf-8-encoded-file","status":"publish","type":"post","link":"https:\/\/blog.box.kr\/?p=154","title":{"rendered":"Reading a UTF-8 Encoded File"},"content":{"rendered":"<p>public static String parseTemplate(String templatePath) {<\/p>\n<p>File aFile = new File(templatePath);<br \/>\nInputStreamReader reader = null;<br \/>\nString template;<br \/>\nStringBuffer temp = new StringBuffer();<br \/>\nint counter = 0;<\/p>\n<p>try {<\/p>\n<p>FileInputStream inStream = new FileInputStream(aFile);<\/p>\n<p>reader = new InputStreamReader(inStream, &#8220;utf8&#8221;);<\/p>\n<p>BufferedReader inBuf = new BufferedReader(reader);<\/p>\n<p>while ((template=inBuf.readLine()) != null) {<\/p>\n<p>if(counter == 0){<\/p>\n<p>template = template.substring(1,template.length());<\/p>\n<p>}<\/p>\n<p>System.out.println(&#8220;inBuf &#8221; + template);<\/p>\n<p>temp.append(template + &#8220;n&#8221;); \/\/ read a line from the file<\/p>\n<p>counter++;<\/p>\n<p>}<\/p>\n<p>inBuf.close();<\/p>\n<p>} catch (Throwable e) {<\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>template=temp.toString();<\/p>\n<p>System.out.println(&#8220;FIO &#8221; + template);<\/p>\n<p>return template;<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, &#8220;utf8&#8221;); BufferedReader inBuf = new BufferedReader(reader); while ((template=inBuf.readLine()) != null) { if(counter == 0){ template = template.substring(1,template.length()); } System.out.println(&#8220;inBuf &#8221; + template); temp.append(template + &#8220;n&#8221;); \/\/ read a line from the file counter++; } inBuf.close(); } catch (Throwable e) { e.printStackTrace(); } template=temp.toString(); System.out.println(&#8220;FIO &#8221; + template); return template; }<\/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-2u","jetpack-related-posts":[{"id":214,"url":"https:\/\/blog.box.kr\/?p=214","url_meta":{"origin":154,"position":0},"title":"UTF-8 \uc778\ucf54\ub529\ub41c \ud30c\uc77c \uc77d\uace0 EUC-KR \ubcc0\uacbd encoded file read","date":"2014-07-22","format":false,"excerpt":"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(\"C:\/utf8test.txt\"); System.out.println(utf8String); System.out.println(new String(utf8String.getBytes(), \"EUC-KR\")); } catch (Exception e) { e.printStackTrace(); } } \u00a0public String readFully(String fileName) throws Exception { File f = new File(fileName); if(!f.exists())\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":154,"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":208,"url":"https:\/\/blog.box.kr\/?p=208","url_meta":{"origin":154,"position":2},"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":[]},{"id":583,"url":"https:\/\/blog.box.kr\/?p=583","url_meta":{"origin":154,"position":3},"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":257,"url":"https:\/\/blog.box.kr\/?p=257","url_meta":{"origin":154,"position":4},"title":"JQuery Ajax \ud1b5\uc2e0\uacfc Spring \uc778\uc218 \ucc98\ub9ac \ubc29\ubc95","date":"2014-07-24","format":false,"excerpt":"JQuery\uc758 Ajax\ud1b5\uc2e0\uc744 \ud558\uba74 \ud558\uae30\uc640 \uac19\uc774 \ubcf4\ub0b8\ub2e4. $.ajax({ type:\"POST\", url:'http:\/\/localhost:8180\/GisProject\/MainService', data:{mydata:JSON.stringify(params)}, datatype:\"json\", success:function(msg){ console.log(msg);}, error:function(xhr,status){ console.log(status);},}); \uc774 \uacbd\uc6b0 \u00a0Spring \uc758 \uae30\ubcf8 Parameter\ub85c\ub294 \ubc1b\uc744 \ubc29\ubc95\uc774 \uc5c6\ub2e4.. \uc65c \ub0d0\uba74. Requert.payload \ud615\uc2dd\uc73c\ub85c \ub118\uc5b4 \uac00\uae30 \ub54c\ubb38\uc5d0.. \u00a0 \uc774\ub97c \ubc1b\uae30 \uc704\ud574\uc120 \ud558\uae30\uc640 \uac19\uc740 \ucc98\ub9ac\uac00 \ud544\uc694 \ud558\ub2e4.. \/\/ Request playload Data \uac00\uc838\uc624\uae30. BufferedReader bfr= req.getReader(); \u00a0\/\/ getReader\ub97c\u2026","rel":"","context":"In &quot;JAVA&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":487,"url":"https:\/\/blog.box.kr\/?p=487","url_meta":{"origin":154,"position":5},"title":"send file sftp java example","date":"2014-12-18","format":false,"excerpt":"public void send (String fileName) { String SFTPHOST = \"host:IP\"; int SFTPPORT = 22; String SFTPUSER = \"username\"; String SFTPPASS = \"password\"; String SFTPWORKINGDIR = \"file\/to\/transfer\"; Session session = null; Channel channel = null; ChannelSftp channelSftp = null; System.out.println(\"preparing the host information for sftp.\"); try { JSch jsch = new\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\/154"}],"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=154"}],"version-history":[{"count":0,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}