1Z0-804 · Question #48
Given the existing destination file, a source file only 1000 bytes long, and the code fragment: What is the result?
The correct answer is A. Overrides the content of the destination file with the source file content. The whole of the FileInputStream will be read (see below). The content of the FileInputStream will overwrite the destination file (see below). A FileInputStream obtains input bytes from a file in a file system. What files are available depends on the host environment…
Question
Given the existing destination file, a source file only 1000 bytes long, and the code fragment:
What is the result?
Exhibit
Options
- AOverrides the content of the destination file with the source file content
- BAppends the content of the source file to the destination file after a new line
- CAppends the content of the source file to the destination file without a break in the flow
- DThrows a runtime exception at line***
How the community answered
(61 responses)- A72% (44)
- B15% (9)
- C8% (5)
- D5% (3)
Explanation
The whole of the FileInputStream will be read (see ** below). The content of the FileInputStream will overwrite the destination file (see *** below). *A FileInputStream obtains input bytes from a file in a file system. What files are available depends on the host environment. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. **FileInputStream.read(byte[] b) B.length bytes of data from this input stream into an array of bytes. b - the buffer into which the data is read. Returns:the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has beenreached. ***FileOutputStream You can construct a FileOutputStream object by passing a string containing a path name or a File 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.
Topics
Community Discussion
No community discussion yet for this question.
