title: save the output from telnet
body: <p>i'm already create the telnet with java, but i have no idea how to save the output into file..
  can help'me??
  this is my code...</p>
  
  <p>this is for connect to the target</p>
  
  <pre><code>     public class telnetsample
       {
       private static TelnetClient telnet = new TelnetClient();
       private InputStream in;
       private PrintStream out;
       private char prompt = '$';
  
       public telnetsample( String server, String username, String password , String command) {
       try {
   // Connect to the specified server
   telnet.connect( server, 23 );
  
   // Get input and output stream references
   in = telnet.getInputStream();
   out = new PrintStream( telnet.getOutputStream() );
  
   // Log the user on
   readUntil( "Username: " );
   write( username );
   readUntil( "Password: " );
   write( password );
       readUntil ("hostname");
       write (command);
  
  
   // Advance to a prompt
   readUntil( prompt + " " );
  }
  catch( Exception e ) {
   e.printStackTrace();
  }
   }
  </code></pre>
  
  <p>this is for read the command on the terminal</p>
  
  <pre><code>    public String readUntil( String pattern ) {
    try {
   char lastChar = pattern.charAt( pattern.length() - 1 );
   StringBuffer sb = new StringBuffer();
   boolean found = false;
   char ch = ( char )in.read();
   while( true ) {
    System.out.print( ch );
    sb.append( ch );
    if( ch == lastChar ) {
      if( sb.toString().endsWith( pattern ) ) {
       return sb.toString();
      }
    }
    ch = ( char )in.read();
   }
   }
   catch( Exception e ) {
   e.printStackTrace();
   }
   return null;
  }
  </code></pre>
  
  <p>for send the command</p>
  
  <pre><code>    public void write( String value ) {
   try {
   out.println( value );
   out.flush();
   System.out.println( value );
  
   }
   catch( Exception e ) {
   e.printStackTrace();
   }
   }
  </code></pre>
  
  <p>for insert username etc</p>
  
  <pre><code>       public static void main( String[] args ) {
  
  
     try {
   telnetsample telnet = new telnetsample( "ip", 
                       "user", 
                       "password",
               "command");
  
  
     }
     catch( Exception e ) {
   e.printStackTrace();
     }
  
     System.exit(0);
     Runtime.getRuntime().exit(0);
  
    }
   }
  </code></pre>