首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 系统运维 >

[转] System.out.println()跟System.out.write()的区别

2013-12-29 
[转] System.out.println()和System.out.write()的区别转至:http://blog.chinaunix.net/uid-26359455-id-3

[转] System.out.println()和System.out.write()的区别
转至:http://blog.chinaunix.net/uid-26359455-id-3130555.html

这两个函数一个是System.out.write()输出字符流,System.out.println()是输出字节流,很简单。看下面这个程序就明白了。


//import java.util.*;public class Test { public static void main(String[] args){// Scanner in = new Scanner(System.in); int a = 65; System.out.write(a); System.out.println("\n"); System.out.println(a); }}


结果:
A

65


测试2:

import java.io.IOException;public class Test2 { public static void main(String[] args) throws IOException{ System.out.write("hello\n".getBytes()); System.out.println("hello");  }}


这两句的效果是一样的。

什么是字符,什么是字节?
1个字节等于8个bit位,每个bit位又0/1两种状态也就是说一个字节可以表示256个状态,计算机里用字节来作为最基本的存储单位。一般来说,英文状态下一个字母或数字(称之为字符)占用一个字节,一个汉字用两个字节表示。在不同的编码方式下一个字符占的字节数不太一样。
简单的来说:字节组成字符

热点排行