2

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
Umair Aziz
  • 1,518
  • 1
  • 19
  • 29
  • When you navigate to the device and right click on the text file to bring up the properties, how is the path listed? Copy/paste it as an edit to the question. – Andrew Thompson Oct 08 '12 at 05:12
  • @AndrewThompson it shows "Location: Computer\Attari's Device" now when i use "run" interface to access that device using above path it says file not found :( same is problem with java code see my edited question as well – Umair Aziz Oct 08 '12 at 05:32
  • No, wherever you are getting that information is not what I mean. Do as I said, navigate to the file, right click (this is Windows, right?) bring up the properties **of the text file** and copy/paste the `Location:` field (it does not look selectable, but it is). – Andrew Thompson Oct 08 '12 at 05:38
  • @AndrewThompson When i navigate to file in connected device in windows 7 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 paste this location in Explorer i navigates to file successfully.. But this doesn't work in Run command and in my java applet code – Umair Aziz Oct 08 '12 at 06:27

1 Answers1

2

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
Umair Aziz
  • 1,518
  • 1
  • 19
  • 29