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

发布于 2024-10-06 00:27:13 字数 69 浏览 1 评论 0原文

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

I am sending a few jpegs (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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

病女 2024-10-13 00:27:13

我将使用 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文