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.Stri开发者_开发问答ng.class, java.lang.Long.class
};
@Override
public Class getColumnClass(int columnIndex)
{
return types[columnIndex];
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex)
{
return false;
}
});
}
Did you try?
FileSystemView.getFileSystemView().getSystemDisplayName(...)
精彩评论