0
출력물을 출력하는 효율적인 방법을 찾고 있었는데 this 문서를 발견했습니다.내 코드가 아무 것도 인쇄하지 않는 이유는 무엇입니까?
그러나 테스트를 위해 다음 코드를 사용했지만 결과가 표시되지 않습니다.
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'를 추가하십시오. 개행을 추가하지 않으면, 많은 텍스트 (afaik)를 푸시하지 않으면 버퍼가 자동으로 지워지지 않습니다. – Carcigenicate
버퍼링을 추가 한 다음 버퍼를 플러시하지 않았습니다. – user2357112
@Carcigenicate 고마워! 그것은 효과가 있었다. –