Copying a file physically in java
Hi,
I want to copy a file from the client to the server machine using java application. I am using JFileChooser .
The problem is that by means of this the copy is possible if the files exist on the same machine but not when the file has to be copied from 1 machine to another.
Thus physically the file does not pass to the server .
The path is the only thing which moves on .
Can this problem be handled in JAVA . I want the file to be copied in it's original form. i.e if the source file is 123.doc then the destination file should be the same , thus i do not want the contents to be copied but the file itself should be copied to the destination .
Regards,
RDeveloper.
I don't see what this has to do with EJB's. But anyway:
> The path is the only thing which moves on .
Then of course this will only work at the local machine. Simply because the client and the server uses and recognizes both the same filesystem.
If you want to upload a file, then there is more to do than just passing the path. I don't know which web framework you're using, but Googling with the keyword "upload" will provide sufficient results. Some examples:
http://www.google.com/search?q=jsp+file+upload
http://www.google.com/search?q=jsf+file+upload
As i had put down , i am not working on jsp. I am trying to pass a file through the java application . In detail ,I have a proper frontend wherein I have a form which allows me selecting files . Files could be in any format , like *.doc,*.jpg etc. The user would attach the file . Actually this file would get copied to the server & it's path would be stored in the database . So whenever the user would try to open the file which he had attached , it would be actually fetched from the server based on the path mentioned.
This is what is intended to happen . I would like to know how can a file pass from the client to the server . It basically is being passed through a remote interface using the File parameter .
For eg: Suppose User.java is a client file from where file C:/built.doc is selected by the user . Now this file is passed to some remote interface to the client file . This should now be moved to the server destination mentioned .
I know that but the question is how to do that .
I do not want to only get the text format. I want the file to be opened in the same format , how it has been saved.
So the process would be , if the file is *.doc then it get's copied to a file , passes to the server & then this word document can be opened.
Similarly wud be for *.xls,*.jpg etc.
Files are just a bunch of bytes (in the right order). So technically you just need to put them in a byte[] (or rather BufferedInputStream/BufferedOutputStream if those are relatively big files and you don't have lot of memory) and then pass it to the other side. Check the java.io API for details.
Here is one useful link: http://www.google.com/search?q=java+io+api+tutorial+site:sun.com
he doubleposted it elsewhere, probably in several places.
He's under the impression that when you send a file over the network the file itself isn't actually sent at all (so he thinks he doesn't need to write code to do that) but the receiver will operate on the actual file on the sending system through some magic.