问题
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;Donot forget add jmtp.dll files (that comes up with jmtp download) as a native library for more info see my answer onimport 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(); } }
http://stackoverflow.com/questions/12798530/including-native-library-in-netbeans
来源:https://stackoverflow.com/questions/12775528/getting-portable-devices-using-java