欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java获得磁盘的卷标,java获得磁盘卷标,Java代码获得磁盘卷标

来源: javaer 分享于  点击 44422 次 点评:96

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"
相关栏目:

用户点评