nerdexam
Oracle

1Z0-819 · Question #188

1Z0-819 Question #188: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-819 to reveal the answer and full explanation for question #188. The question stem and answer options stay visible for context.

Question

Given: import java.io.File; import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Arrays; public class Test { public static void main(String[] args) throws Exception { String fileName = "file.txt"; String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ByteBuffer buffer = ByteBuffer.wrap(str.getBytes()); // line 1 fileChannel.write(buffer); fileChannel.close(); } } You want to obtain the FileChannel object on line 1. Which code fragment will make the code compile?

Options

  • Atry (FileChannel fileChannel = new FileOutputStream(fileName).getChannel()) {}
  • Btry (FileChannel fileChannel = new FileOutputStream(new File(fileName)).getChannel()) {}
  • Ctry (FileChannel fileChannel = new FileChannel(new FileOutputStream(fileName))) {}
  • Dtry (FileChannel fileChannel = new FileOutputStream(fileName).getChannel()) {}

Unlock 1Z0-819 to see the answer

You've previewed enough free 1Z0-819 questions. Unlock 1Z0-819 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Full 1Z0-819 Practice