1 16 package examples.nntp; 17 18 import java.io.IOException ; 19 import org.apache.commons.net.nntp.NNTPClient; 20 import org.apache.commons.net.nntp.NewsgroupInfo; 21 22 30 31 public final class newsgroups 32 { 33 34 public final static void main(String [] args) 35 { 36 NNTPClient client; 37 NewsgroupInfo[] list; 38 39 if (args.length < 1) 40 { 41 System.err.println("Usage: newsgroups newsserver"); 42 System.exit(1); 43 } 44 45 client = new NNTPClient(); 46 47 try 48 { 49 client.connect(args[0]); 50 51 list = client.listNewsgroups(); 52 53 if (list != null) 54 { 55 for (int i = 0; i < list.length; i++) 56 System.out.println(list[i].getNewsgroup()); 57 } 58 else 59 { 60 System.err.println("LIST command failed."); 61 System.err.println("Server reply: " + client.getReplyString()); 62 } 63 } 64 catch (IOException e) 65 { 66 e.printStackTrace(); 67 } 68 finally 69 { 70 try 71 { 72 if (client.isConnected()) 73 client.disconnect(); 74 } 75 catch (IOException e) 76 { 77 System.err.println("Error disconnecting from server."); 78 e.printStackTrace(); 79 System.exit(1); 80 } 81 } 82 83 } 84 85 } 86 87 88 | Popular Tags |