PrintWriter out = new PrintWriter(s.getOutputStream(),true);
String line = null;
while((line=bufr.readLine())!=null)
{
out.println(line);
}
1.out.println(line);和System.out.println(line);有何区别呢?分别在啥时候用?
2.PrintWriter out = new PrintWriter(s.getOutputStream(),true);中的s.getOutputStream(),true是怎么回事?
希望大牛们解答下,非常感谢! 作者: 李尧 时间: 2013-3-28 11:00
1.println 是打印流的一个方法 至于那个out 是你自己的定义的 printWriter
System.out.println是标准输出到控制台
2..PrintWriter out = new PrintWriter(s.getOutputStream(),true) true表示自动刷新,flase表示不自动刷新.
也就是这个构造方法 PrintWriter(Writer out, boolean autoFlush)
具体可以查看API的作者: fighting 时间: 2013-3-28 11:01
看看文档吧,其中System的out属性是这样的:
out
public static final PrintStream out
The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.
For simple stand-alone Java applications, a typical way to write a line of output data is:
System.out.println(data)
See the println methods in class PrintStream.
是根据主调用环境输出在标准输出窗口的,比如windows的dos窗口
autoFlush - A boolean; if true, the println, printf, or format methods will flush the output buffer 作者: 郑show 时间: 2013-3-28 11:32
out.println()输出到客户端。
在out.println()中,out是response的实例,是以response为对象进行流输出的,即将内容输出到客户端。
System.out.println()打印在控制台当中。
System.out.println()用的是标准输出流,这个是输出在控制台上的. 如果想打印在页面,简单点的方法是:
out.print( "要打印的内容" );
其实在正规的网站建设中,是从来不用out.println()的,都是直接使用标签。作者: 郑show 时间: 2013-3-28 11:38
2.PrintWriter out = new PrintWriter(s.getOutputStream(),true);中的s.getOutputStream(),true是怎么回事?
这应该是socket通信程序中的一个语句。其中的s应该是一个socket对象。s.getOutputStream()就是返回一个服务器与客户端的输出流,true是对PrintWriter out 而言,就是强行把缓冲区的数据输出。s.getOutputStream()返回的是一个节点流,在它上面又套上了一个处理流PrintWriter ,便于输出数据。作者: 王杰123 时间: 2013-3-28 13:00 本帖最后由 王杰123 于 2013-3-28 13:07 编辑
1。
System 类包含一些有用的类字段和方法。它不能被实例化。 在 System 类提供的设施中,有标准输入(static InputStream in )、标准输出(static PrintStream out)和错误输出流(static PrintStream err );System.out.println()用的是标准输出流,这个是输出在控制台上的.
out 是PrintWriter的对象,PrintWriter类里有方法println()。