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 are
a. 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 are
a. 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 5

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


rao

rao

correct

Sarah

Sarah

Why?

byte[] body = new byte[fsSource.Lenght]
fsHeader.Write(header, 0, header.lenght)
fsBody.Write(body, 20, body.lenght)

It’s incorrect?

Davis

Davis

Nope.

I think the code in the question is wrong.
Because, those header and body are two separate streams. so it has to be read from the position zero.

It should be corrected as below.
fsSource.Read(body,20,body.length)

But the answers are the ones given.

#OpenForSuggestions

Mike

Mike

The answer is correct. It is
fsSource.Read(body, 0, body.Length);
The offset has to be 0 because with
fsSource.Read(header, 0, header.Length);
we already advanced the pointer of the fsSource to 20. As we do not reset that pointer we continue and get only the rest from position 20 on.