Listing articles in a newsgroup in Java

There is an undocumented Sun package called sun.net.nntp. Following
example shows you how to list the first 20 articles in comp.lang.java.programmer
of the free newsserver news.uni-stuttgart.de.
Beware:
Why Developers Should Not Write Programs That Call ‘sun’ Packages

import sun.net.nntp.*;
import java.io.*;
 
public class Main {
   public static void main(String[] args) throws IOException {
      String newsserver = "news.uni-stuttgart.de";
      String newsgroup = "comp.lang.java.programmer";
 
      NntpClient nntp = new NntpClient(newsserver);
      //nntp.setGroup(newsgroup);
      NewsgroupInfo group = nntp.getGroup(newsgroup);
 
      for (int i = group.firstArticle; i <= group.lastArticle; i++) {
         try {
            System.out.println("Article nr: " + i);
            InputStream article = nntp.getArticle(i);
            BufferedReader br = new BufferedReader(new InputStreamReader(article));
            String line;
            while ((line = br.readLine()) != null) {
               System.out.println(line);
            }
         }
         catch (NntpProtocolException e) {
            System.out.println(e);
         }
      }
   }
}