PeakGen
PeakGen

Reputation: 23035

How can you access USB from cross-platform Java?

I need to copy some files from a PC into a pen drive. I visited JUSB package description, but it is only for windows. So, is there any easy and platform independent way to copy files from computer to USB drive using Java?

Upvotes: 2

Views: 2985

Answers (2)

ollo
ollo

Reputation: 25380

You can take a look at libUsb Java Bindings a javabinding for libUsb. Btw. the jUSB API seems to support Linux too (package: usb.linux), maybe this article can help you: Access USB devices from Java applications

Upvotes: 1

Adriaan Koster
Adriaan Koster

Reputation: 16209

You don't need to worry about the fact that it's a USB drive; when the user inserts the device it is recognized by the OS and shows up as a mounted drive in your filesystem. Then you can just use java.io.File and friends to access it. Additional tip: use org.apache.commons.io.FileUtils as a handy toolkit to make many common file-related tasks easier.

If you need to detect the new USB device automatically in Java, that's a bit tricky. See this question.

Upvotes: 2

Related Questions