Add content to a file

Report a typo

Fill in the gap in line 5 by creating an instance of an output stream which uses sample.txt as a destination. Constructor should accept sampleFile object.

Suppose that sample.txt exists and has the following content: My favorite program language is .

File sampleFile = new File("sample.txt");
byte[] content = new byte[] {'J', 'a', 'v', 'a'}; 

try {
    OutputStream outputStream = __;
    outputStream.write(content);
    outputStream.close();
} catch (Exception e) {
    System.out.println("Error!");
}

The correct program should change the file's content in the following way: My favorite program language is Java

Enter a short text
___

Create a free account to access the full topic