Portable Device Path on Windows

前端 未结 3 568
一整个雨季
一整个雨季 2020-12-11 05:36

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..

相关标签:
3条回答
  • 2020-12-11 06:04

    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

    0 讨论(0)
  • 2020-12-11 06:13

    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 "\\.\"

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

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

    0 讨论(0)
  • 2020-12-11 06:16

    The solution to above problem using JMTP library on https://code.google.com/p/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.

    0 讨论(0)
提交回复
热议问题