|
Read messages from a news server |
|
|
This tip shows how to read messages from a news server.
import sun.net.nntp.*;
import java.io.*;
public class NntpGetGroup {
public static void main(String[] args)
throws IOException {
/*
** pass your news server, newsgroup as parameter
** eg. java NttpPost news.server.com alt.test
*/
NntpClient c = new NntpClient(args[0]);
c.setGroup(args[1]);
NewsgroupInfo ni = c.getGroup(args[1]);
int first = ni.firstArticle;
int last = ni.lastArticle;
for (int i = first; i <= last; i++) {
String aLine;
BufferedReader br = null;
InputStream anArticle = null;
try {
anArticle = c.getArticle(i);
br = new BufferedReader(new InputStreamReader(anArticle));
System.out.println("-----------------\nArticle " + i);
while ((aLine = br.readLine()) != null) {
System.out.println(aLine);
}
}
catch (NntpProtocolException e) {
/*
** probably a cancelled article, just skip it
*/
}
}
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.