1Z0-804 · Question #113
Assuming the port statements are correct, which two (three?) code fragments create a one- byte file?
The correct answer is A. OutputStream fos = new FileOutputStream(new File("/tmp/data.bin")); B. OutputStream fos = new FileOutputStream ("/tmp/data.bin"); C. OutputStream fos = new FileOutputStream (new File ("/tmp/data.bin")). B: Create DataOutputStream from FileOutputStream public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputS tream("C:/demo.txt"); DataOutputStream dos = new DataOutputStream(fos); The FileOutputStream class is a subclass of OutputStream…
Question
Assuming the port statements are correct, which two (three?) code fragments create a one- byte file?
Options
- AOutputStream fos = new FileOutputStream(new File("/tmp/data.bin"));
- BOutputStream fos = new FileOutputStream ("/tmp/data.bin");
- COutputStream fos = new FileOutputStream (new File ("/tmp/data.bin"));
- DOutputStream fos = new FileOutputStream ("/tmp/data.bin");
How the community answered
(41 responses)- A80% (33)
- D20% (8)
Explanation
B: Create DataOutputStream from FileOutputStream public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputS tream("C:/demo.txt"); DataOutputStream dos = new DataOutputStream(fos); The FileOutputStream class is a subclass of OutputStream. You can construct a FileOutputStream object by passing a string containing a path name or a File object. You can also specify whether you want to append the output to an existing file. public FileOutputStream (String path) public FileOutputStream (String path, boolean append) public FileOutputStream (File file) public FileOutputStream (File file, boolean append) With the first and third constructors, if a file by the specified name already exists, the file will be To append to an existing file, pass true to the second or fourth constructor. Note 2:public class DataOutputStreamextends FilterOutputStreamimplements DataOutput A data output stream lets an application write primitive Java data types to an output stream in a portable An application can then use a data input stream to read the data back in.
Topics
Community Discussion
No community discussion yet for this question.