开发者

Any ideas on how to send a filename attributed with a file when using BufferedOuput/Input Stream?

I am sending a few jpe开发者_运维技巧gs (and sometimes zip) files. I was wondering if anyone knew of a way to send the filename (or a custom filename) with the file, rather than definin


I would use a DataOutputStream/DataInputStream and use writeUTF()/readUTF() the filename before sending the length of the file, followed by the file.

Basicly you have to have a small protocol of your own which sends the infomration you need.

Something like

DataOutputStream dos
byte[] bytes;

dos.writeUTF(filename);
dos.writeInt(bytes.length);
dos.write(bytes);

to read

DataInputStream dis
String filename = dis.readUTF();
int length = dis.readInt();
byte[] bytes = new byte[length];
dis.readFully(bytes);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜