`

println方法和write方法的区别

    博客分类:
  • JESE
 
阅读更多
println会向缓冲区输出内容,并在内容后输出一个换行符。将内容作为一行输出到另一端。write只是向缓冲区输出内容。没有换行符。而print方法则跟write一样,只是将null转换为字符串'null'。

即:writer.println("msg") == writer.write("msg"); + writer.write("\n") ;

如果用write()方法输出内容并flush后,用在IO的另一端用readline来读取内容,会阻塞IO、阻塞线程。
如果用println()方法输出内容并flush后,IO另一端的readline则会读到内容。

 

分享到:
评论

相关推荐

    java 中 System.out.println()和System.out.write()的区别

    主要介绍了 java 中 System.out.println()和System.out.write()的区别.的相关资料,需要的朋友可以参考下

    人工智能-项目实践-搜索引擎-java实验1-实现搜索引擎的倒排索引数据结构

    如果写文本文件,推荐使用PrintWriter,当创建好PrintWriter对象后,调用其println和print方法可以将字符串一行行的写入到文本文件,使用方法与System.out.println, System.out.print完全一样 具体使用方法,请见...

    IO输入输出留

    // 测试renameto方法 移动和更改问价名 private static void test3() { File f1 = new File("d:/rand.txt"); File f2 = new File("d:/r.txt"); // 刚改前查看文件是否存在 System.out.println(f1.getName...

    计算机(专升本)Java程序设计复习资料.doc

    方法的重载和覆盖(重写)有什么区别? 3. 简述抽象类与接口的异同。 4. 简述JDBC访问数据库的步骤。 二、编程题 1. 定义一个类Circle,计算并输出圆(半径=3)的面积 2. 在D盘创建文件test.txt,文件中的内容为...

    javaweb数据写入到excel

    System.out.println("jxl write RowsExceededException: "+e.getMessage()); } catch (WriteException e) { System.out.println("jxl write WriteException: "+e.getMessage()); } catch (IOException e) { ...

    FileOutputStream将乘法口诀表写入指定文件

    System.out.println("九九乘法表写入文件成功 ..."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { fos.close()...

    服务器下载文件

    String file_unique = request.getParameter("file_unique"); String date = file_unique.substring(0,7... toClient.write(buffer); System.out.println(buffer.toString()); toClient.flush(); toClient.close();

    java-实验报告.doc

    bufferWrite.write(str); bufferWrite.newLine(); } bufferRead.close(); bufferWrite.close(); } catch(IOException e){ System.out.println(e.toString()); } } } 3. 结果截图: 4. 实验分析: 1. 改进程序,使得...

    用java程序对表导出Excel的源代码

    import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; import jxl.write.biff.RowsExceededException; import pojo.UserInfo; import service.UserInfoService; ...

    java io读取文件到String

    System.out.println("方法1用时"+ (endTime-beginTime) + "ms"); return ret; } public static String loadAFileToStringDE2(File f) throws IOException { long beginTime = System.currentTimeMillis(); ...

    编写简单的代理服务器(java源码)

    基本原理: 代理服务器打开一个端口接收浏览器发来的访问某个站点的请求,从...out.write(buf,0,n); } out.close(); s.close(); } catch (IOException e) { System.out.println("Exception:"+e); } } };

    IO流的使用,自己的心得

    String writeString = "testOutPut:1231"; int tempLength = 2; StringBuffer bs = new StringBuffer(); int each = 0; try { ops = new FileOutputStream(filePath); byte ...

    java将png转为gif

    这个包是从jdk1.7中将jdk的源码拆下来打的包,可以解决在1.4下无法将png完美转换成gif的问题。这个转换非常完美。测试的话,main函数里面写 ...System.out.println(UtilImage.write(image, "gif", file));

    文件发送程序.doc

    System.out.println(s); File file = new File(s); String name = file.getName(); try { socket = new Socket("192.168.1.5",10000); } catch (IOException e) { e.printStackTrace(); ...

    3Java SE(下).doc

    file.canWrite(); file.canRead(); file.canExecute(); 是否为隐藏文件:file.isHidden(); 2.使用File创建一个新文件 ---->在当前项目根目录下创建一个名为demo.txt的文件 若是在当前目录下,"./"是可以...

    SCoop Arduino

    Serial.println(uS/US_ROUNDTRIP_CM); if(value>400&&(sound>80||uS/US_ROUNDTRIP_CM)){ analogWrite(rPin,255); analogWrite(ledPin,0); delay(5000); }else{ analogWrite(rPin,0); analogWrite(ledPin,0)...

    Excel数据操纵-jar包-jxl.jar

     很简单和插入单元格的方式一样,不过就是参数多了些,WritableImage这个类继承了Draw,上面只是他构造方法的一种,最后一个参数不用了说了,前面四个参数的类型都是double,依次是 x, y, width, height,注意,这里...

    通过java操作excel表格的工具类库jxl

     很简单和插入单元格的方式一样,不过就是参数多了些,WritableImage这个类继承了 Draw,上面只是他构造方法的一种,最后一个参数不用说了,前面四个参数的类型都是double,依次是 x, y, width, height,注意,这里...

    二十三种设计模式【PDF版】

    设计模式之 Factory(工厂方法和抽象工厂) 使用工厂模式就象使用 new 一样频繁. 设计模式之 Builder 汽车由车轮 方向盘 发动机很多部件组成,同时,将这些部件组装成汽车也是一件复杂的工作,Builder 模式就是将这...

    android访问网络get post 源代码项目

    04 System.out.println(userName+"-"+password); 05 DataOutputStream dos = new DataOutputStream(response.getOutputStream()); 06 if (userName != null && password != null) { 07 if (userName.length() ...

Global site tag (gtag.js) - Google Analytics