Java 关闭PrintWriter后无法写入新的HTML内容
您好,我无法在关闭PrintWriter后添加新内容。有没有其他方法可以做到这一点Java 关闭PrintWriter后无法写入新的HTML内容,java,Java,您好,我无法在关闭PrintWriter后添加新内容。有没有其他方法可以做到这一点 String myCurrentDir = System.getProperty("user.dir"); File htmlFile = new File(TestRunner.FilePath+"\\Footer.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(htmlFile)); PrintWri
String myCurrentDir = System.getProperty("user.dir");
File htmlFile = new File(TestRunner.FilePath+"\\Footer.html");
final OutputStream out = new BufferedOutputStream(new FileOutputStream(htmlFile));
PrintWriter writer = new PrintWriter(out);
writer.println("<HTML>");
writer.println("<HEAD>");
writer.println("<title>Report Foot</title>");
writer.println("<link rel=\"stylesheet\" type=\"text/css\" href=\""+myCurrentDir+"/CSS/Report.CSS\">");
writer.println("</HEAD>");
writer.println("<body class = 'footer'>");
writer.println("<B>");
writer.println("Total : "+TotalTCs);
writer.println("<span class='passed'>Passed : "+0+"</span>");
writer.println("<span class='failed'>Failed : "+0+"</span>");
writer.println("<span class='warned'>Warned : "+0+"</span>");
writer.println("<span class='norun'>No Run : "+0+"</span>");
writer.println("</B>");
writer.println("<BR/>");
writer.println("<BR/>");
writer.close();//after this any content doesn't gets saved in html
writer.println("@ABC DEF XYZ");
writer.println("</body>");
writer.println("</HTML>");
writer.close();
System.out.println("Footer Written");
String myCurrentDir=System.getProperty(“user.dir”);
File htmlFile=新文件(TestRunner.FilePath+“\\Footer.html”);
final OutputStream out=新的BufferedOutputStream(新的FileOutputStream(htmlFile));
PrintWriter=新的PrintWriter(输出);
writer.println(“”);
writer.println(“”);
writer.println(“报告脚”);
writer.println(“”);
writer.println(“”);
writer.println(“”);
writer.println(“”);
writer.println(“总计:+TotalTCs”);
writer.println(“通过:+0+”);
writer.println(“失败:+0+”);
println(“警告:+0+”);
println(“无运行:+0+”);
writer.println(“”);
writer.println(“
”);
writer.println(“
”);
writer.close()//在此之后,任何内容都不会保存在html中
writer.println(“@ABC DEF XYZ”);
writer.println(“”);
writer.println(“”);
writer.close();
System.out.println(“页脚写入”);
流生命周期是:
新流
)写入
,追加
,等等)关闭
)PrintWriter::close()
doc:
关闭流并释放所有关联的系统资源
用它
设置out=null
内部PrintWriter
。
关闭后,您将在任何调用write
、flush
、print
等时获得IOException
。
这些方法在执行任何操作之前调用ensureOpen()
private void ensureOpen() throws IOException {
if (out == null)
throw new IOException("Stream closed");
}
}
流生命周期是:
新流
)写入
,追加
,等等)关闭
)PrintWriter::close()
doc:
关闭流并释放所有关联的系统资源
用它
设置out=null
内部PrintWriter
。
关闭后,您将在任何调用write
、flush
、print
等时获得IOException
。
这些方法在执行任何操作之前调用ensureOpen()
private void ensureOpen() throws IOException {
if (out == null)
throw new IOException("Stream closed");
}
}
为什么你需要在中间关闭它?为什么你认为你仍然可以在关闭它之后写内容?为什么你需要在中间关闭它?为什么你认为你仍然可以在关闭它之后写内容?