wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes copying files to pendrives via java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "copying files to pendrives via java" Watch "copying files to pendrives via java" New topic
Author

copying files to pendrives via java

sahil sethi
Greenhorn

Joined: Oct 14, 2013
Posts: 2
Hello everyone

M a new user here and in java too, i working on application that need to copy some files from my one of folder to pen drive (removable disk) attached ,so how can i do that,actually i donot have any idea how it gonna implement so please help me out in this.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18154
    
    8

Hi Sahil, welcome to the Ranch!

If I'm not mistaken, once you plug them into your computer's USB port and get them connected, they are just part of the file system. So you can just write to them like any other drive. If you're using Windows, for example, then your pen drive might be mapped to the E: drive, so you just write to files on the E: drive.

Did that answer your question, or is there more to it than that?
sahil sethi
Greenhorn

Joined: Oct 14, 2013
Posts: 2
But How to Detect that drive??? and please tell me procedure/code to copy files please(as m a new user)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18154
    
    8

I don't know what you mean when you say "How to detect that drive?" It isn't your program's job to detect the drive. The operating system will do that and assign a drive letter (if it's Windows) or some other identification (if it's some other O/S). Perhaps you meant to ask how to find out which drive letter Windows assigned, or something like that?

As for how to copy a file, here's some example code which I found in about half a minute using the Google keywords java copy files example: Copy a file.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1950
    
  28
sahil sethi wrote:But How to Detect that drive??? and please tell me procedure/code to copy files please(as m a new user)

Some time ago I wrote some code to detect the insert and removal of removable drives, you can find it here: http://www.keang.co.uk/drive.html
NOte: This uses a basic polling approach and I haven't looked at later versions of Java to see if there is now a better way to go about this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: copying files to pendrives via java
 
Similar Threads
copy command and renaming
how see jdk logs
Copying file from Java to System clipboard help
I want to import single-spaced code
Accessing contents of a jar file