How should you complete the relevant code?

DRAG DROP
You are creating a method that will split a single input file into two smaller output files.
The method must perform the following actions:
Create a file named header.dat that contains the first 20 bytes of the input file.
Create a file named body.dat that contains the remainder of the input file.
You need to create the method.
How should you complete the relevant code? (To answer, drag the appropriate code
segments to the correct locations in the answer area. Each code segment may be used
once, more than once, or not at all. You may need to drag the split bar between panes or
scroll to view content.)

DRAG DROP
You are creating a method that will split a single input file into two smaller output files.
The method must perform the following actions:
Create a file named header.dat that contains the first 20 bytes of the input file.
Create a file named body.dat that contains the remainder of the input file.
You need to create the method.
How should you complete the relevant code? (To answer, drag the appropriate code
segments to the correct locations in the answer area. Each code segment may be used
once, more than once, or not at all. You may need to drag the split bar between panes or
scroll to view content.)

Answer:



Leave a Reply 9

Your email address will not be published. Required fields are marked *


Mediterrano

Mediterrano

last part of the answer is wrong
correct answer is
fsBody.Write(body, 20, body.Length);

koernomop

koernomop

last part should be fsBody.Write(body, 0, body.Length);

Fippy Darkpaws

Fippy Darkpaws

Answer is correct. Stream is already positioned at 20 when second read executes.

j

j

Answer is correct.

Andre Aranha

Andre Aranha

3 – 4 – 7: I tested and researched around.

“offset” and “count” parameters of “Stream.Read” / “Stream.Write” methods ALWAYS refer to the array you are sending in the first parameter.

The position of fsSource advances as you Read it, unless you .Seed on it.

kasp

kasp

Your explanation is right but you should conclude that the right answer is 3-4-6

kasp

kasp

if you use
fsBody.Write(body, 20, body.Length);
you get the following exception:

Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.