您的位置:首页 > 编程语言 > Java开发

Java基础知识_毕向东_Java基础视频教程笔记(19-21 IO流)

2017-09-07 15:17 776 查看
  18天-06-IO流
  字节流和字符流

1 import java.io.IOException;
2 import java.io.UnsupportedEncodingException;
3 class Demo
4 {
5     public static void main(String[] args)throws IOException
6     {
7         encodeShow("test", "gbk");
8         encodeShow("test", "utf-8");
9         encodeShow("test", "GB2312");
10         encodeShow("test", "ascii");
11         encodeShow("test", "unicode");
12         encodeShow("test", "ISO8859-1");
13     }
14     public static void encodeShow(String param, String charset)
15         throws UnsupportedEncodingException
16     {
17         String str = param;
18         sop("source string: " + str + "     encode is: " + charset);
19         byte[] bt = str.getBytes(charset);
20         for (byte b : bt)
21         {
22             sop("encode binary: " + Integer.toBinaryString(b));
23         }
24         String t = new String(bt, charset);
25         sop("encode string: " + t);
26         sop("");
27     }
28     private static void sop(Object obj)
29     {
30         System.out.println(obj);
31     }
32 }


编码转换
换行符: Linux:\n    windows:\r\n    Mac:\r
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: