thufir

weather, but no log

Sep 14th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package weather;
  2.  
  3. import examples.IOUtil;
  4. import java.io.BufferedWriter;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.OutputStreamWriter;
  8. import java.io.Writer;
  9. import java.net.InetAddress;
  10. import java.net.UnknownHostException;
  11. import org.apache.commons.net.telnet.TelnetClient;
  12.  
  13. public class Weather {
  14.  
  15.     public Weather() {
  16.     }
  17.  
  18.     public static void main(String[] args) throws UnknownHostException, IOException {
  19.         int port = 3000;
  20.         InetAddress host = InetAddress.getByName("rainmaker.wunderground.com");
  21.         TelnetClient tc = new TelnetClient();
  22.         tc.connect(host, port);
  23.        
  24.         FileOutputStream weatherLog = new FileOutputStream("weather.log");
  25.         IOUtil.readWrite(tc.getInputStream(), tc.getOutputStream(), System.in, System.out);
  26.         IOUtil.readWrite(tc.getInputStream(), tc.getOutputStream(), System.in, weatherLog);
  27.  
  28.         Writer writer = new BufferedWriter(new OutputStreamWriter(weatherLog, "utf-8"));
  29.         writer.flush();
  30.         writer.close();
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment