0

我正在发送一些 jpeg(有时是 zip)文件。我想知道是否有人知道将文件名(或自定义文件名)与文件一起发送的方法,而不是定义

4

1 回答 1

0

在发送文件长度之前,我会使用 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);
于 2010-12-03T10:52:27.800 回答