使用java获取便携式设备

使用java获取便携式设备

本文介绍了使用java获取便携式设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 java 小程序访问在 Windows 7 中显示为 便携式设备 的设备(其中包含 windows CE" 应用程序)中的某些文件...

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

我的设备路径就像

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

同样我使用了

"\\.\Attari's Device\myfile.txt"

但它导致了同样的错误告诉我如何使用 java 小程序访问便携式设备

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

此外,当我打开此文件时,它会自动放置在我计算机的 temp 文件中.我也在使用签名小程序,所以没有文件访问被拒绝的问题

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

我也使用了

File.listRoots()

但它也没有列出附加的便携式设备我必须使用java小程序在便携式设备中编写一些文件

but it also does not list attached portable devicesI have to write some file in portable device using java applet

推荐答案

我在

http://code.google.com/p/jmtp/

这是我的代码


    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();

    }
}

不要忘记将 jmtp.dll 文件(与 jmtp 下载一起提供)添加为本机库以获取更多信息,请参阅我在

http://stackoverflow.com/questions/12798530/including-native-library-in-netbeans

这篇关于使用java获取便携式设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:01