public class Receive {
final static String name = "E:\\2.zip";//接收文件储存位置
final static int port = 9999;
final static int databig = 8192;
public static void main(String[] args){
File file = new File(name);
byte[] data = new byte[databig];
long big = 0;
long count = 0;
try {
ServerSocket server = new ServerSocket(port);
System.out.println("等待发送端连接");
Socket socket = server.accept();
System.out.println("连接成功");
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
BufferedInputStream in = new BufferedInputStream(socket.getInputStream(), databig);
DataInputStream in2 = new DataInputStream(socket.getInputStream());
//接收文件大小
big = in2.readLong();
System.out.println(big);
public class Send {
final static String name = "E:\\2.zip";
final static String ip = "19.168.43.01";
final static int port = 9999;
final static int filebig = 8192;
public static void main(String[] args) {
File file = new File(name);
long big = file.length();
System.out.printf("文件总大小(Byte): ");
System.out.println(big);
byte[] data = new byte[filebig];
long count = 0;
try {
Socket socket = new Socket(ip, port);
FileInputStream in = new FileInputStream(file);
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream(), filebig);
DataOutputStream out2 = new DataOutputStream(socket.getOutputStream());
//发送文件大小
out2.writeLong(big);
out2.flush();