3

I'm making a basic file browser, and in one mode, it loops through the file roots and lists them. I have it get the icon, drive letter, last-modified date, drive name, and size in bytes. These all work but drive name. Does anyone know how to get this? Here is a basic version of my code:

public static final byte ICON_INDEX = 0, NAME_INDEX = 1, MOD_INDEX = 2, TYPE_INDEX = 3, SIZE_INDEX = 4;
public String headers[] = new String[5];

private void updateFileView()
{
  java.io.File[] roots = java.io.File.listRoots();
  Object[][] files = new Object[roots.length][headers.length];
  for (int i = 0; i < files.length; i++)
  {
    files[i][ICON_INDEX] = javax.swing.filechooser.FileSystemView.getFileSystemView().getSystemIcon(roots[i]);
    files[i][NAME_INDEX] = roots[i];
    files[i][MOD_INDEX] = new java.util.Date(roots[i]).toString();
    files[i][TYPE_INDEX] = ???;
    files[i][SIZE_INDEX] = roots[i].length();
  }
  headers[ICON_INDEX] = "Icon";
  headers[NAME_INDEX] = "Drive Letter";
  headers[MOD_INDEX] = "Last Date Modified";
  headers[TYPE_INDEX] = "Drive Name";
  headers[SIZE_INDEX] = "Size in Bytes";
  displayTable.setModel(new javax.swing.table.DefaultTableModel(files, headers)
  {
    private static final long serialVersionUID = 1L;
    Class[] types = new Class[]
    {
      javax.swing.Icon.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Long.class
    };

    @Override
    public Class getColumnClass(int columnIndex)
    {
      return types[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex)
    {
      return false;
    }
  });
}
madth3
  • 7,275
  • 12
  • 50
  • 74
Ky -
  • 30,724
  • 51
  • 192
  • 308

1 Answers1

4

Did you try?

FileSystemView.getFileSystemView().getSystemDisplayName(...)
Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • huh... Looks like I gotta use the `javax.swing.filechooser` package has all I need... Ironic, isn't it? – Ky - Dec 07 '10 at 21:57
  • 6
    Yes, and you should look there first BEFORE posting a question. This is your 6th question on this topic and you keep getting referred to the same place. Do some basic problem solving and learn to read the API FIRST! – camickr Dec 07 '10 at 21:59