[英]Why does my code not print anything?
我一直在尋找一種有效的方法來打印輸出,因此找到了這篇文章。
但是,我使用以下代碼對其進行了測試,但它不顯示任何輸出。
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.IOException;
class NewClass {
public static void main(String args[] ) throws Exception {
Printy p=new Printy();
p.printLine("JAVA");
}
}
class Printy
{
private final BufferedWriter bw;
public Printy()
{
bw=new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(String str)throws IOException
{
bw.append(str);
}
public void printLine(String str)throws IOException
{
print(str);
bw.append("\n");
}
public void close()throws IOException
{
bw.close();
}
}
這里有什么問題以及如何正確實施?
您需要flush
緩沖區,否則文本將位於緩沖區中而不被打印。
附加文本后,添加一個flush
請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.