Windows 上的便携式设备路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2481300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:09:43  来源:igfitidea点击:

Portable Device Path on Windows

javawindowsdevicetabletdrive-letter

提问by Ripei

I've actually got an Windows/Java Question. I've got a plugged-in device which I want to access via Java. Normally you can access an e.g. USB-Stick via the Drive letter... but this tablet is displayed by Windows as a "Portable Device"... which means, that the Path is something like "Computer\Archos 5S" and there is no Drive letter.

我实际上有一个 Windows/Java 问题。我有一个插入式设备,我想通过 Java 访问它。通常,您可以通过驱动器号访问例如 USB 记忆棒……但此平板电脑被 Windows 显示为“便携式设备”……这意味着,路径类似于“计算机\爱可视 5S”,并且有没有驱动器号。

I want to access a file on this device via Java, but I am not able to figure out the correct path to it. There is a similar question out there, but without a productive answer. Or is there another way to access this device via Java?

我想通过 Java 访问此设备上的文件,但我无法找出正确的路径。那里有一个类似的问题,但没有有效的答案。或者还有其他方法可以通过 Java 访问此设备吗?



Actually I've not solved this problem... I am still not able to access such a device via java.

其实我还没有解决这个问题......我仍然无法通过java访问这样的设备。

At the moment I am trying to access a windows ShellFolder in Java. A Shellfolder like: "Shell:::{35786D3C-B075-49b9-88DD-029876E11C01}"

目前我正在尝试使用 Java 访问 Windows ShellFolder。Shellfolder 像:“Shell:::{35786D3C-B075-49b9-88DD-029876E11C01}”

Is this possible with Java? Recently I uncovered the sun.awt class "ShellFolder"... is this the wanted feature?

这可以用 Java 实现吗?最近我发现了 sun.awt 类“ShellFolder”……这是想要的功能吗?

thanks for your help Ripei

感谢您的帮助 Ripei

回答by Umair Aziz

The solution to above problem using JMTP library on https://code.google.com/p/jmtp/

使用https://code.google.com/p/jmtp/ 上的JMTP 库解决上述问题

Here is my code

这是我的代码

package 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();

    }
}

Do not forget add jmtp.dll files (that comes up with jmtp download) as a native library. For more info, see my answer on Including Native Library in Netbeans.

不要忘记添加 jmtp.dll 文件(与 jmtp 下载一起提供)作为本机库。有关更多信息,请参阅我关于在 Netbeans 中包含本机库的回答。

回答by John Knoeller

Like *nix systems, all devices (including drives) have paths that are part of a common root, this is normally hidden from users because they use the drive letters which are aliases to these fundamental paths, but you can also use full device paths by prefixing the path with "\\.\"

像 *nix 系统一样,所有设备(包括驱动器)都有属于公共根目录的路径,这通常对用户隐藏,因为他们使用作为这些基本路径别名的驱动器号,但您也可以使用完整的设备路径路径前缀 "\\.\"

For instance, on my machine D: translates as "\Device\HarddiskVolume1"and can be accessed by passing "\\.\HarddiskVolume1"to CreateFile.

例如,在我的机器上 D: 转换为"\Device\HarddiskVolume1"并且可以通过传递"\\.\HarddiskVolume1"给 CreateFile来访问。

So the path to your device is probably "\\.\Archos 5s".

所以你的设备的路径可能是"\\.\Archos 5s".

回答by peter

you can always download and install the Windows mobile developer Powertoys (http://www.microsoft.com/download/en/details.aspx?id=10601) and copy from and to the device using the command line utility cecopy, which you can run from any programming language. There are other options there too, but it's most targeted at .Net

您可以随时下载并安装 Windows 移动开发人员 Powertoys (http://www.microsoft.com/download/en/details.aspx?id=10601) 并使用命令行实用程序 cecopy 从设备复制或复制到设备可以从任何编程语言运行。那里也有其他选择,但它最针对 .Net