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