正如 JAVA 文档中给出的那样,每当出现 java.io.IOException 时,变量“trouble”就会设置为 true。我写了一个程序:
import java.io.*;
class First
{
public static void main(String[] args) throws Exception
{
File f = new File("a.txt");
PrintStream ps = new PrintStream(f);
f.delete();
ps.write(65);
boolean b = ps.checkError();
System.out.println(b); //Output: false
ps.close();
}
}
即使我在写入之前删除了文件,为什么 checkError() 方法没有返回 true?请举例说明当变量 'trouble' 设置为 true 并且 checkError() 方法返回 true 时。
最佳答案
根据JavaDoc :
checkError
returnstrue
if and only if this stream has encountered anIOException
other thanInterruptedIOException
, or thesetError
method has been invoked.
关于java - PrintStream 对象的 checkError() 方法在什么条件下返回 true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40019942/