Read messages from a newsserver (this howto is deprecated)Tag(s): DEPRECATED
This snippet uses an undocumented Sun package [JDK1.1]
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
*/
}
}
}
}
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com