import java.io.*;
public class Write1 
{
public static void main(String args[])
{
try
{
System.out.print("Input: ");
int count,n=512;
byte buffer[] = new byte[n];
count = System.in.read(buffer); //读取标准输入流
FileOutputStream wf = new FileOutputStream("Write1.txt");
//创建文件输出流对象
wf.write(buffer,0,count); //写入输出流
wf.close(); //关闭输出流
System.out.println("Save to Write1.txt!");
}
catch (IOException ioe)
{
System.out.println(ioe);
}
catch (Exception e)
{
System.out.println(e);
}
}
}红字的count的作用是什么??  谢谢!

解决方案 »

  1.   

    记录buffer这个byte数组的上界,以便在  wf.write(buffer,0,count);   中使用
      

  2.   

    JSP讨论②群   29402605  学习JSP的道路是艰辛的也是快乐的!希望大家能在一起学习~互相交流经
    不要长期不说话哦~
    论坛建设中...
      

  3.   

    count = System.in.read(buffer);这句话是怎么纪录有效数据的长度为输入的长度呢?
      

  4.   

    count 代表的是 read(buffer); 这个buffer从Stream中读取到的数据的长度 如我输入一个a字符再敲一下回车 count=3 如果输入一个中文字符 count=4 
      

  5.   

    查JAVADOC看看,System.in.read()方法的返回值是什么;再查wf.write(buffer,0,count);中的count参数是什么意义。这才是解决问题和培养解决问题的能力的正道。请多指教。