PrintWriter在Java中写入()vs print()方法 [英] PrintWriter write() vs print() method in Java

查看:99
本文介绍了PrintWriter在Java中写入()vs print()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

write() print()方法在 PrintWriter中有什么区别 class in Java?

解决方案


print()格式化输出,而write()只是输出给定的字符
。 print()处理许多参数类型,使用String.valueOf()将它们转换为
可打印字符串,而write()
只处理单个字符,字符数组和字符串。

为了说明这个区别,写(int)把参数解释为
单个字符,print(int)把整数
转换成一个字符串。写(49)打印一个1,而打印(49)
打印49。

来源:< a href =http://www.coderanch.com/t/398792/java/java/write-print =noreferrer> http://www.coderanch.com/t/398792/java/java/书写打印


What is the difference between write() and print() methods in PrintWriter class in Java?

解决方案

print() formats the output, while write() just prints the characters it is given. print() handles many argument types, converting them into printable strings of characters with String.valueOf(), while write() just handles single characters, arrays of characters, and strings.

To illustrate the difference, write(int) interprets the argument as a single character to be printed, while print(int) converts the integer into a character string. write(49) prints a "1", while print(49) prints "49".

source: http://www.coderanch.com/t/398792/java/java/write-print

这篇关于PrintWriter在Java中写入()vs print()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆