how to send a complete (.txt,.doc) file in java
i am making a client server program in java, a portion of which requires to send a complete file (.txt or .docx) file from client to server. I am not sure how to do it, i have tried using this webpage http://www.rgagnon.com/javadetails/java-0542.html , but it seems that it don't wor开发者_StackOverflowk correctly in form + multi-threaded application, is there any other way to send a complete file from client to server?
Any help/suggestions are appreciated...
regards usama
In principle you have to read the file on your client application, open an OutputStream to the server, and write the contents of the file to this stream. On the server you read from the other end of the stream.
Depending on your architecture, you either will use a new socket-pair for the file transfer, or somehow embed it into your existing communication protocol.
It would be better to use a Messaging Application for your purpose. I would recommend using JMS. I personally use ActiveMQ . If this does not suit your need then try out Apache Mina. It would abstract you from the Network Programming.
精彩评论