Java:列出已插入的摄像头

我的程序目前获得了一个使用File.listRoots()插入计算机的驱动器列表。 但是,当我将相机或MP3播放器直接插入计算机(而不是插入存储卡)时,它没有列出,也没有Windows资源管理器中的驱动器号。 例如,这是我的相机的位置:

 Computer\Canon PowerShot SD750\Removable storage 

如何列出没有驱动器号的摄像机/其他设备? 我认为这将需要某种类型的JNI库,但我显然不确定。

谢谢!

PS出于绝望,我确实试图列出Computer\的内容; 它当然不起作用。


更新 :我在这里找到了这个问题: Windows上的便携式设备路径 ; 这正是我遇到的问题,但那里没有解决方案。

Java 7在这个领域有一些看起来很有前途的类,比如这个: http : //download.java.net/jdk7/docs/api/java/nio/file/FileSystem.html

假设您需要它也可以在Java 6上运行,我建议运行shell脚本并解析其输出。 在Windows上你可以在Unix / MacOS X mount等上运行mountvol。当然解析输出会有点乏味,你不得不担心你的应用程序运行的每个操作系统,但是嘿,至少……不确定是什么。 … 有用?

以下是一些在Windows上看起来很有用的示例代码:

 strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume") For Each objItem In colItems WScript.Echo "Automount: " & objItem.Automount WScript.Echo "Block Size: " & objItem.BlockSize WScript.Echo "Capacity: " & objItem.Capacity WScript.Echo "Caption: " & objItem.Caption WScript.Echo "Compressed: " & objItem.Compressed WScript.Echo "Device ID: " & objItem.DeviceID WScript.Echo "Dirty Bit Set: " & objItem.DirtyBitSet WScript.Echo "Drive Letter: " & objItem.DriveLetter WScript.Echo "Drive Type: " & objItem.DriveType WScript.Echo "File System: " & objItem.FileSystem WScript.Echo "Free Space: " & objItem.FreeSpace WScript.Echo "Indexing Enabled: " & objItem.IndexingEnabled WScript.Echo "Label: " & objItem.Label WScript.Echo "Maximum File Name Length: " & objItem.MaximumFileNameLength WScript.Echo "Name: " & objItem.Name WScript.Echo "Quotas Enabled: " & objItem.QuotasEnabled WScript.Echo "Quotas Incomplete: " & objItem.QuotasIncomplete WScript.Echo "Quotas Rebuilding: " & objItem.QuotasRebuilding WScript.Echo "Serial Number: " & objItem.SerialNumber WScript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas WScript.Echo "Supports File-Based Compression: " & _ objItem.SupportsFileBasedCompression WScript.Echo Next 

这是我为电子书阅读器输出的输出:

 Automount: True Block Size: 4096 Capacity: 999120896 Caption: G:\ Compressed: Device ID: \\?\Volume{8e3b4ce5-a124-11e0-9d2b-e30c5839642d}\ Dirty Bit Set: False Drive Letter: G: Drive Type: 2 File System: FAT32 Free Space: 663683072 Indexing Enabled: Label: PocketBook9 Maximum File Name Length: 255 Name: G:\ Quotas Enabled: Quotas Incomplete: Quotas Rebuilding: Serial Number: 1276177233 Supports Disk Quotas: False Supports File-Based Compression: False 

使用JMTP库解决上述问题

  http://code.google.com/p/jmtp/ 

这是我的代码

    包jmtp; 

 import be.derycke.pieter.com.COMException; import be.derycke.pieter.com.Guid; import java.io.*; import java.math.BigInteger; import jmtp.PortableDevice; import jmtp.*; public class Jmtp { public static void main(String[] args) { PortableDeviceManager manager = new PortableDeviceManager(); PortableDevice device = manager.getDevices()[0]; // Connect to my mp3-player device.open(); System.out.println(device.getModel()); System.out.println("---------------"); // Iterate over deviceObjects for (PortableDeviceObject object : device.getRootObjects()) { // If the object is a storage object if (object instanceof PortableDeviceStorageObject) { PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object; for (PortableDeviceObject o2 : storage.getChildObjects()) { // // BigInteger bigInteger1 = new BigInteger("123456789"); // File file = new File("c:/JavaAppletSigningGuide.pdf"); // try { // storage.addAudioObject(file, "jj", "jj", bigInteger1); // } catch (Exception e) { // //System.out.println("Exception e = " + e); // } // System.out.println(o2.getOriginalFileName()); } } } manager.getDevices()[0].close(); } } 

Donot忘记添加jmtp.dll文件(提供jmtp下载)作为本机库获取更多信息,请参阅我的回答

  http://stackoverflow.com/questions/12798530/including-native-library-in-netbeans 

这可能不是您正在寻找的答案,但是将它们分配给驱动器号而不是选项? 您通常可以使用“我的电脑”>右键单击>“管理”>“存储”,在Windows上使用USB设备手动执行此操作。

JMF中的CaptureDeviceManager(Java媒体框架)可以帮助你,但我有点怀疑它。

也许你可以看看Morena Framework http://www.gnome.sk/Twain/jtp.htmlv (似乎是开源的,但有点贵;虽然有一个免费的评估版),它适用于TWAIN兼容扫描仪/摄像机(Windows / MAC)或SANE兼容(Linux或其他unix风格),要获取连接设备列表,您可以这样做:

 import SK.gnome.morena.*; import SK.gnome.twain.*; public class Test { public static void main(String[] args) throws Exception { TwainSource[] sources=TwainManager.listSources(); if(sources == null) return; for(int i = 0; i < sources.length; i++) { System.out.println("Twain source is: " + ts.toString()); } } } 

也许这可能有所帮助,如果不是我认为JMF可能是一个可能的解决方案。