Mega Code Archive

 
Categories / Java / File Input Output
 

Get icon for file type

import java.io.File; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class Main {   public static void main(String[] args) throws Exception {     File file = new File(args[0]);     sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder(file);     Icon icon = new ImageIcon(sf.getIcon(true));     System.out.println("type = " + sf.getFolderType());     JLabel label = new JLabel(icon);     JFrame frame = new JFrame();     frame.getContentPane().add(label);     frame.pack();     frame.setVisible(true);   } }