This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Copy/moving a file from one location to Server location. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Copy/moving a file from one location to Server location." Watch "Copy/moving a file from one location to Server location." New topic
Author

Copy/moving a file from one location to Server location.

shiva valanukonda
Greenhorn

Joined: Sep 27, 2010
Posts: 25

Hi,

I want to copy/move an Excel file from source location to Server location.
I supposed to do it manually by uploading the file using browse button in Server url.
Can we do it automatically using java code by eliminating this browse mechanism.
Please give me your valuable suggestions on this.

Thanks in advance
VSRK
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2849
    
  11

You could poll a known directory for the Excel files, and transfer them as they appear. There can be issues with synchronization though. For example, your process could see the Excel file and try to start transferring it before it has been fully created, or while its still being edited. One common trick is to write the file with a different name, like .myfile.xls, then rename it to myfile.xls when you're ready for it to transfer. Another trick is to keep a .lock file in the directory, and delete it when all the files in the directory are ready.

This question isn't specifically about I/O streams, so I'm going to move it over to general Java, where you'll probably get a lot more useful suggestions!
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 174

In Windows at least, you can't "move" (renameTo()) files across file systems but you can copy them and then delete the original.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19678
    
  18

Carey Brown wrote:In Windows at least, you can't "move" (renameTo()) files across file systems but you can copy them and then delete the original.

Interesting. I've been able to successfully do just that multiple times, even to different physical hard drives or to a Windows share.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Copy/moving a file from one location to Server location.