请问我用getInputStream()方法在Telnet服务器得到数据流后,怎样把得到数据流的文本内容保存到文档中呢?部分代码:
TelnetClient telnet = new TelnetClient();
in = telnet.getInputStream();用下面的方法可以把流的内容打印出来,但是我不知道怎么把这些文本内容保存在文本文件中,请高手帮助下。谢谢了!!!!
char ch = (char) in.read();
System.out.print(ch);

解决方案 »

  1.   


    FileOutputStream fos = new FileOutputStream("1.txt");byte b = (byte)in.read();while(b != -1){
        fos.write(b);
        b = (byte)in.read(); 
    }fos.close();
    in.close();
      

  2.   

    FileInputStream input = new FileInputStream(temp);
                        FileOutputStream output = new FileOutputStream("test.txt");
                        byte[] b = new byte[1024 * 5];
                        int len;
                        while ((len = input.read(b)) != -1) {
                            output.write(b, 0, len);
                        }
                        output.flush();
                        output.close();
                        input.close();