|
Get a list of headers from a newsgroup |
|
|
This tip shows a way to obtain the list of headers from a newsgroup.
import sun.net.nntp.*;
import java.io.*;
public class NntpHeader {
public static void main(String[] args)
throws IOException {
/*
** pass your news server as parameter
** eg. java NttpPost news.server.com
*/
NntpClient c = new NntpClient(args[0]);
String newsgroup = "alt.test";
c.setGroup(newsgroup);
NewsgroupInfo ni = c.getGroup(newsgroup);
int first = ni.firstArticle;
int last = ni.lastArticle;
for (int i = first; i <= last; i++) {
try {
InputStream theHeader = c.getHeader(i);
BufferedReader br = new BufferedReader(new
InputStreamReader(theHeader));
String theLine;
System.out.println("-----------------\nHeader " + i + "/" + last);
while ((theLine = br.readLine()) != null)
System.out.println(theLine);
}
catch (NntpProtocolException ne) {
/*
** 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.