195k views
4 votes
Which statement is used to create a file object that will append data to an existing file? BufferedWriter salesdata =

new BufferedWriter(new FileWriter("out.dat", false);.
new BufferedWriter(new FileWriter("out.dat", true);.
new BufferedWriter(new FileWriter("out.dat");.
new BufferedWriter(new FileWriter("out.dat", append);.

User Zasuk
by
5.6k points

2 Answers

1 vote

Answer:

Answer:

BufferedWriter salesdata = new BufferedWriter(new FileWriter("out.dat", true);.

Step-by-step explanation:

The statement BufferedWriter salesdata = new BufferedWriter(new FileWriter("out.dat", true); can be used to create a file object that will append data to an existing file.

Here, BufferedWriter class is used to create text from an output stream.

Here, FileWriter is used to create the file from the text. The constructor for FileWriter is FileWriter (String filename, boolean append).

Here, filename is string ("out.dat") is provided and the append is boolean can be either true (if the text has to be appended at the end of the file) or false (if the text hasn't to be appended at the end of the file).

So, option (b) is correct.

Option (a) is not correct as it indicates the text shouldn't be appended at the end of the file as the boolean is false.

Option (c) is not correct as it doesn't mean to append as there is no boolean true indicated in the constructor.

Option (d) is not correct as there is not such kind of syntax.

Click to let others know, how helpful is it

The

User Accumulator
by
5.5k points
6 votes

Answer:

BufferedWriter salesdata = new BufferedWriter(new FileWriter("out.dat", true);.

Step-by-step explanation:

  • The statement BufferedWriter salesdata = new BufferedWriter(new FileWriter("out.dat", true); can be used to create a file object that will append data to an existing file.
  • Here, BufferedWriter class is used to create text from an output stream.
  • Here, FileWriter is used to create the file from the text. The constructor for FileWriter is FileWriter (String filename, boolean append).
  • Here, filename is string ("out.dat") is provided and the append is boolean can be either true (if the text has to be appended at the end of the file) or false (if the text hasn't to be appended at the end of the file).
  • So, option (b) is correct.
  • Option (a) is not correct as it indicates the text shouldn't be appended at the end of the file as the boolean is false.
  • Option (c) is not correct as it doesn't mean to append as there is no boolean true indicated in the constructor.
  • Option (d) is not correct as there is not such kind of syntax.

User Essam
by
6.5k points