Java Reference
In-Depth Information
String line3 = "I to her cottage bent my way,";
String line4 = "Beneath an evening moon.";
try (FileOutputStream fos = new FileOutputStream(destFile)){
// Write all four lines to the output stream as bytes
fos.write(line1.getBytes());
fos.write(lineSeparator.getBytes());
fos.write(line2.getBytes());
fos.write(lineSeparator.getBytes());
fos.write(line3.getBytes());
fos.write(lineSeparator.getBytes());
fos.write(line4.getBytes());
// Flush the written bytes to the file
fos.flush();
// Display the output file path
System.out.println("Text has been written to " +
(new File(destFile)).getAbsolutePath());
}
catch (FileNotFoundException e1) {
FileUtil.printFileNotFoundMsg(destFile);
}
catch (IOException e2) {
e2.printStackTrace();
}
}
}
Text has been written to C:\book\javabook\luci2.txt
Input Stream Meets the Decorator Pattern
Figure 7-5 depicts the class diagram that includes some commonly used input stream classes. You can refer to the
API documentation of the java.io package for the complete list of the input stream classes. The comments in the
class diagram compare input stream classes with the classes in the decorator pattern. Notice that the class diagram
for the input streams is similar to the class diagram for your drink application, which was also based on the decorator
pattern. Table 7-1 compares the classes in the decorator pattern, the drink application, and the input streams.
 
 
Search WWH ::




Custom Search