// Displays Windows Volume Labels
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.filechooser.FileSystemView;
public class VolLabels
   {
   // pattern to search for _(X:)
   static final Pattern p = Pattern.compile( " \\([A-Za-z]:\\)" );

   public static void main(String[] args)
      {
      FileSystemView v = FileSystemView.getFileSystemView();
      for ( File f : File.listRoots() )
         {
         final String full = v.getSystemDisplayName( f );
         final int length = full.length();
         // Remove the trailing _(X:)
         final String chopped;

         final Matcher m = p.matcher( full );
         if ( m.find() )
            {
            chopped = full.substring( 0, m.start() ).trim();
            }
         else
            {
            chopped = full.trim();
            }
         out.println( " full:[" + full + "]     chopped:[" + chopped + "]" );
         }
      }
   }