Getting Portable Devices using java

六月ゝ 毕业季﹏ 提交于 2019-12-12 09:09:40

问题


I am trying to access some files in a device (having "windows CE" application in it) that appears as portable device in windows 7 using java applet....

My device path is like

 "Computer\Attari's Device\myfile.txt" 
Now i am trying to access file from it using the same address but it gives path error or file not found.

Similarly i used

"\\.\Attari's Device\myfile.txt"
but it resulted in same error tell me how to access portable devices using java applet

When i navigate to connected device and right-click on file and see it's properties then it shows it's location as

Location:  Computer\Attari's Device

Also when i open this file it is automatically placed in temp files of my computer. I am using Signed Applet as well so there is no issue of file access denied

I also used

File.listRoots()
but it also does not list attached portable devices I have to write some file in portable device using java applet

回答1:


I found the solution to above problem using JMTP library on

http://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();

    }
}

Donot forget add jmtp.dll files (that comes up with jmtp download) as a native library for more info see my answer on
http://stackoverflow.com/questions/12798530/including-native-library-in-netbeans


来源:https://stackoverflow.com/questions/12775528/getting-portable-devices-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!