Oracle Java SE 21 Developer Professional 1z0-830 Question # 6 Topic 1 Discussion

Oracle Java SE 21 Developer Professional 1z0-830 Question # 6 Topic 1 Discussion

1z0-830 Exam Topic 1 Question 6 Discussion:
Question #: 6
Topic #: 1

Which of the followingisn'ta correct way to write a string to a file?


A.

java

Path path = Paths.get("file.txt");

byte[] strBytes = "Hello".getBytes();

Files.write(path, strBytes);


B.

java

try (BufferedWriter writer = new BufferedWriter("file.txt")) {

writer.write("Hello");

}


C.

java

try (FileOutputStream outputStream = new FileOutputStream("file.txt")) {

byte[] strBytes = "Hello".getBytes();

outputStream.write(strBytes);

}


D.

java

try (PrintWriter printWriter = new PrintWriter("file.txt")) {

printWriter.printf("Hello %s", "James");

}


E.

None of the suggestions


F.

java

try (FileWriter writer = new FileWriter("file.txt")) {

writer.write("Hello");

}


Get Premium 1z0-830 Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.