Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
shiva valanukonda
Greenhorn
Posts: 26
Hibernate jQuery Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 1635
22
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic