通过 BufferedWriter 发送大字符串

发布于 2024-11-03 19:11:02 字数 123 浏览 0 评论 0原文

使用 BufferedWriter 发送一个大字符串(5Mb,一个 xml 文件,一行)是否存在问题?

它的工作速度非常快。是否有一些黄金法则不允许行长超过几K?然后我必须编写一些额外的文件传输协议......:-(

is there some problem sending a big String (5Mb, one xml file, all i one line) with a BufferedWriter?

It works very fast. Is there some golden rule disallowing lines longer than a few K? Then I would have to write some extra filetransfer protocol... :-(

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

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

发布评论

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

评论(4

乄_柒ぐ汐 2024-11-10 19:11:02

BufferedWriter 本身无法决定事情进展的速度。它只是为你做一些缓冲。这实际上取决于您要写入的内容……在 LAN 上,5MB 并不是特别大,但通过移动连接则需要很长时间。

换句话说:这取决于。不存在禁止排长队的“黄金法则”……但我们不知道您正在使用什么协议。在您的特定协议中,可能存在大小限制。如果您想要更详细的答案,您必须为您的问题添加更多细节......

The BufferedWriter itself won't determine how quickly things go. It's just going to do some buffering for you. It really depends on what you're then writing to... on a LAN, 5MB isn't particularly huge, but over a mobile connection it would take a long time.

In other words: it depends. There's no "golden rule" disallowing long lines... but then we don't know what protocol you're using. It's possible that in your particular protocol there is a size limit. If you want a more detailed answer, you'll have to add more detail to your question...

别再吹冷风 2024-11-10 19:11:02

如果它有效,那么它就有效。如果不起作用,请将字符串分成块。

If it works, then it works. If it doesn't work, break the string into chunks.

冰之心 2024-11-10 19:11:02

这 5Mb 行是你唯一写的东西吗?如果是这样,那么 BufferedWriter 不会在它包装的 Writer 上添加任何内容。如果您正在进行大量小写入并希望将它们缓冲成更大的块以发送到底层 Writer,那么 BufferedWriter 会很有用,这可能会产生开销write() 方法(例如磁盘寻道时间/旋转延迟)。

Is this 5Mb line the only thing you're writing? If so then a BufferedWriter isn't adding anything over the Writer it wraps. A BufferedWriter is useful if you're doing lots of small writes and want to buffer them up into larger chunks to send to the underlying Writer, which may have an overhead on it's write() method (for example disk seek time/rotation delay).

浅忆流年 2024-11-10 19:11:02

接收方可能会遇到一个小问题 - 这是否接受这么长的队伍?
有些程序可能准备接收长线,但针对短线的常见情况进行了优化,因此使用长线会减慢它们的速度。

另外,一行的具体组成也取决于系统 - 大多数情况下,它意味着后面有一个 \n (Unix),或者一个 \r\n ( DOS/Windows/大多数公共互联网协议)。

另外,请注意写入的行对 BufferedWriter write 方法的调用是两个正交的事情 - 您可以多次调用 write 只写一行,或者您可以只用一次 write 调用来写多行。

What might be a little problem is the receiving side - does this accept such long lines?
Some programs might be prepared to receive long lines, but are optimized for the common case of short lines, thus using long lines would slow them down.

Also, what exactly consists a line is system dependent, too - most often it means that there comes a \n after it (Unix), or a \r\n (DOS/Windows/most public Internet protocols).

Also, take note that lines written and calls to the BufferedWriter write methods are two orthogonal things - you can make multiple calls to write writing only one line at all, or you can write multiple lines with only one write call.

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