SCJP Book, IO section: Is this a typo or is there a reason it would look like this?
Posted
by iamchuckb
on Stack Overflow
See other posts from Stack Overflow
or by iamchuckb
Published on 2010-05-14T18:27:02Z
Indexed on
2010/05/14
18:44 UTC
Read the original article
Hit count: 284
My question is about line 4, where the new PrintWriter is created with the constructor taking the FileWriter fw as a parameter. I don't understand the use of chaining the BufferedWriter bw to FileWriter if it isn't used later on in the actual writing. Can Java apply chaining in a way that bw still somehow affects the rest of the program?
16. try {
17. FileWriter fw = new FileWriter(test);
18. BufferedWriter bw = new BufferedWriter(fw, 1024);
19. PrintWriter out = new PrintWriter(fw);
20. out.println("<html><body><h1>");
21. out.println(args[0]);
22. out.println("</h1></body></html>");
23. out.close();
24. bw.close();
25. fw.close();
26. }catch(IOException e) {
27. e.printStackTrace();
28. }
I think it is probably a typo and they meant to use bw as the parameter for PrintWriter out but like the title says, I'm new to this.
Thanks to all in advance.
© Stack Overflow or respective owner