Portable Device Path on Windows
Asked Answered
E

3

7

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.

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?


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

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

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

thanks for your help Ripei

Emplacement answered 20/3, 2010 at 0:12 Comment(2)
I have connected my unit to my PC in the "MSC" mode, but I cannot see it on my computer: This mode - MSC (Mass Storage Class) - is only for Linux computers which will recognize a plugged-in ARCHOS Internet Tablet as an external hard drive. For advanced Windows users, it is possible to obtain drivers (use at your own risk - NOT supported by ARCHOS tech support team) from the Internet that will allow you to mount Ext3 type partitions as an external hard drive on your Windows computer. wiki.archosfans.com/index.php?title=Archos_FAQStradivarius
More... What do the options MSC and MTP in the USB Connection mode do for me? These are the protocols for how it connects to a computer. MSC (Mass Storage Class) is the most common USB connection method. MTP (Media Transport Protocol) is an intelligent transport system for regular files and Windows Media Player files. If you are using Windows, you should connect in MTP mode. If you are using Linux, then you should connect in MSC mode.Stradivarius
R
4

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.

Reproachless answered 11/10, 2012 at 13:59 Comment(0)
C
2

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

Cinnamon answered 20/3, 2010 at 0:26 Comment(4)
thanks... this seems to be the right way although my problem isn't solved up to now. I am not able to access any drive or the "Archos 5S" via the "\\.\ - Paramter. But i found this link: docs.plt-scheme.org/reference/windowspaths.html Then i tried to access a drive via "\\?\C:" and this works... but it doesn't work for "\\?\Archos 5S". do you have any idea why? thanks in advance ripeiEmplacement
Try using GetLogicalDriveStrings and QueryDosDevice maybe the your device already has an alias even if it isn't a drive letter.Cinnamon
see this simple C program for an example of enumerating all devices. pastebin.com/Y3pGu5hSCinnamon
thank you very much. Actually I am not able to find an equivalent Java-methode... cause I've to use Java. There is only "File.listRoots()" which returns all available Drive-letters.Emplacement
S
0

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

Sacred answered 18/3, 2012 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.