Java File () how to specify the path to the connected device

Question:

I wrote a simple utility that changes the names of files in a directory. When choosing a directory on the hard drive, everything is ok, but it was originally planned to use the utility for files on the player. When I use it on the player, I catch a NullPointerException , the path is as follows: Компьютер\WALKMAN\Storage Media\MUSIC\ Where to dig?

Answer:

Here is a very similar question with answers, I hope it helps you:

https://stackoverflow.com/a/12841327 Using JMTP library https://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();

    }
}

You must add the jmtp.dll files (included in the jmtp download file) as native libraries .

Scroll to Top