一.IO

1.IO概念

·输入流:把能够读取一个字节序列的对象称为输入流(百度百科)

·输出流:把能够写一个字节序列的对象称为输出流(百度百科)

从定义上看可能会让你感到困惑,这里解释一下:];                 //先写到缓存中,然后再一起写到其他外设中

  • int length = 0;
  • while ((length=in.read(buf))!=-1){                //-1 represent the end of the file is reached    ,
  • //字节一个一个地读入到内存
  • System.out.println(new String(buf,0,length)); //需要将int转为字节,如果为中文的话输出乱码字符  ,
  • //此处其实是写出到了外设(控制台)上,System.out返回的是PrintStream对象
  • }
  • } catch (IOException e) {
  • e.printStackTrace();
  • }finally {
  • if (in != null){
  • try {
  • in.close();
  • } catch (IOException e) {
  • e.printStackTrace();
  • }
  • }
  • }
  • }