uyaseen
uyaseen

Reputation: 1201

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 work 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

Upvotes: 0

Views: 745

Answers (2)

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74750

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.

Upvotes: 1

Abhishek
Abhishek

Reputation: 1031

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.

Upvotes: 1

Related Questions