java 中 System.out.println()和System.out.write()的区别
作者:lqh 时间:2021-09-17 04:30:52
java 中 System.out.println()和System.out.write()的区别.
这两个函数一个是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个状态,计算机里用字节来作为最基本的存储单位。一般来说,英文状态下一个字母或数字(称之为字符)占用一个字节,一个汉字用两个字节表示。在不同的编码方式下一个字符占的字节数不太一样。
简单的来说:字节组成字符
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.chinaunix.net/uid-26359455-id-3130555.html
标签:java,println(),write()
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring Boot 应用的热部署配置方法
2022-03-26 23:36:56
![](https://img.aspxhome.com/file/2023/7/67097_0s.jpg)
MyBatis-Plus 集成动态多数据源的实现示例
2023-06-26 17:56:35
spring boot项目没有mainClass如何实现打包运行
2021-10-24 11:29:20
Java命名规则详细总结
2023-11-14 12:20:55
javaweb上传下载实例完整版解析(上)
2021-07-31 05:40:23
![](https://img.aspxhome.com/file/2023/4/63114_0s.jpg)
详解Java中的反射机制和动态代理
2023-11-27 15:41:00
![](https://img.aspxhome.com/file/2023/1/60911_0s.png)
OpenCV实现直线检测并消除
2023-07-12 20:44:36
![](https://img.aspxhome.com/file/2023/3/92493_0s.jpg)
Java 开启多线程常见的4种方法
2023-11-23 02:30:10
![](https://img.aspxhome.com/file/2023/0/58580_0s.png)
Android版本更新实例详解
2023-08-05 21:54:54
![](https://img.aspxhome.com/file/2023/1/85981_0s.png)
详解java Collections.sort的两种用法
2023-11-28 09:30:31
![](https://img.aspxhome.com/file/2023/3/60473_0s.png)
浅谈Java中Int、Integer、Integer.valueOf()、new Integer()之间的区别
2023-10-29 20:08:53
![](https://img.aspxhome.com/file/2023/4/68154_0s.png)
Java 深入探讨设计模式之原型模式篇
2023-11-16 17:37:59
![](https://img.aspxhome.com/file/2023/3/64553_0s.png)
在IntelliJ IDEA中为自己设计的类库生成JavaDoc的方法示例
2023-11-25 09:49:02
Java实现经典游戏打砖块游戏的示例代码
2021-06-25 13:30:16
![](https://img.aspxhome.com/file/2023/1/61331_0s.png)
Java Set集合及其子类HashSet与LinkedHashSet详解
2023-11-26 11:39:35
![](https://img.aspxhome.com/file/2023/0/59510_0s.png)
Android实现的数字格式化用法示例
2023-09-30 09:03:28
Spring中自定义数据类型转换的方法详解
2022-10-09 02:56:51
Java面向对象编程(封装/继承/多态)实例解析
2023-11-11 11:33:09
SpringBoot2.0解决Long型数据转换成json格式时丢失精度问题
2022-10-31 16:56:24
![](https://img.aspxhome.com/file/2023/1/61521_0s.png)
Kafka Producer中的消息缓存模型图解详解
2022-05-03 06:00:13
![](https://img.aspxhome.com/file/2023/2/61012_0s.jpg)