I want to send pdfs to a client webservice url using Java. How can this be done?
A few simple steps. I will add some terms between brackets for googling.
Here is some sample code.
InputStream in = new FileInputStream(file);
OuputStream os = socket.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
int n;
byte[] b = new byte[1024 * 16];
while ((n = in.read(b)) != -1)
{
dos.writeByte(1); // tell the server a buffer is coming
dos.writeInt(n); // tell it the how big the buffer is
dos.write(b, 0, n); // write the buffer
}
dos.writeByte(0); // tell the server no more buffers are coming.
dos.flush();
Now, it is up to you to write the server part of it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.