客户端.
package net.demo;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class SendFile {
public static void main(String[] args) throws Exception {
new SendFile().sendFile(null, "D:\\a.jpg", 8821);
}
public void sendFile(String romteUrl, String path, int port)
throws Exception {
File file = getFile(path);
Socket scket = new Socket("localhost",port);
DataOutputStream dos = new DataOutputStream(scket.getOutputStream());
DataInputStream dis = new DataInputStream(new BufferedInputStream(
new FileInputStream(path)));
int size = 1024;
byte[] bufArry = new byte[size];
dos.writeUTF(file.getName());
dos.flush();
dos.writeLong(file.length());
dos.flush();
while (true) {