ตัวอย่าง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | package demo.file; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class ReadUTF8EncodedExample { /** * @param args */ public static void main(String[] args) { try { File fileDir = new File( "C:\\users\\nopphanan7\\UTF-8-file.txt" ); BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream(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()); } } } |
1 | ทดสอบการอ่านไฟล์ UTF- 8 |
0 comments:
Post a Comment