java获得磁盘的卷标,java获得磁盘卷标,Java代码获得磁盘卷标
Java代码获得磁盘卷标import java.io.*;import javax.swing.filechooser.*;public class VolumeLabel { private VolumeLabel() { } public static void main(String[] args) { System.out.println("\"" + get(args[0]) + "\""); } public static String get(String path) { FileSystemView view = FileSystemView.getFileSystemView(); File dir = new File(path); String name = view.getSystemDisplayName(dir); if (name == null) { return null; } name = name.trim(); if (name == null || name.length() < 1) { return null; } int index = name.lastIndexOf(" ("); if (index > 0) { name = name.substring(0, index); } return name; }}
输出:Running from c:\temp>java VolumeLabel c:"temp">java VolumeLabel c:\"HARDDISK1"