我正在制作一个基本的文件浏览器,在一种模式下,它循环遍历文件根并列出它们。我得到了图标,驱动器号,最后修改日期,驱动器名称和大小(以字节为单位)。这些都可以,但驱动器名称。有谁知道如何得到这个?这是我的代码的基本版本:
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;
}
});
}
答案 0 :(得分:4)
你试过吗?
FileSystemView.getFileSystemView().getSystemDisplayName(...)