简体   繁体   English

如何在java中编写缓冲行?

[英]How to write line buffered in java?

In C you can set the buffering using the function 在C中,您可以使用该功能设置缓冲

int setvbuf (FILE *stream, char *buf, int mode, size_t size); int setvbuf(FILE * stream,char * buf,int mode,size_t size);

How can I set the buffering in Java so that is behaves the same as _IOLBF (for line buffering)? 如何在Java中设置缓冲,使其与_IOLBF(用于行缓冲)的行为相同? Which class does this? 这是哪一堂课?

I know that there is BufferedWriter, but this does full buffering. 我知道有BufferedWriter,但这可以完全缓冲。

You can use PrintWriter with autoflush. 您可以将PrintWriter与autoflush一起使用。

PrintWriter pw = new PrintWriter(out, /* autoflush */ true);

pw.println(somethingToPrint); // will flush as well.

This is not exactly the same as it will push out data whenever the buffer files (esp for very long lines) and it won't flush if you write text with newlines in it but use print() to print the line. 这与每当缓冲区文件(特别是非常长的行)推出数据时不完全相同,如果你用其中的换行符编写文本但是使用print()来打印行,它就不会刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM