有关如何在使用BufferedOuput / Input Stream时发送归档文件的文件名的任何想法?

我发送了一些jpegs(有时是zip)文件。我想知道是否有人知道用文件发送文件名(或自定义文件名)的方法,而不是definin     
已邀请:
我会使用DataOutputStream / DataInputStream并在发送文件长度之前使用writeUTF()/ readUTF()文件名,然后是文件。 基本上,你必须拥有自己的小协议,它可以发送你需要的信息。 就像是
DataOutputStream dos
byte[] bytes;

dos.writeUTF(filename);
dos.writeInt(bytes.length);
dos.write(bytes);
阅读
DataInputStream dis
String filename = dis.readUTF();
int length = dis.readInt();
byte[] bytes = new byte[length];
dis.readFully(bytes);
    

要回复问题请先登录注册