File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,21 +46,21 @@ tags:
4646 StreamWriter sw = new StreamWriter(filePath);
4747 sw.WriteLine("Hello World!!");
4848 ` ` `
49-
49+
5050 <details><summary>Solution</summary>
5151 This program would
52-
52+
5353 # . Create a file located at `filePath`,
5454 # . Store in the file "Hello World!!", followed by a new line.
55-
55+
5656 This program is unsafe because :
57-
57+
5858 # . It does not close the file properly,
5959 # . It can throw exceptions if e.g., `filePath` cannot be accessed by the program,
6060 # . It possibly overwrites the file located at `filePath`.
61-
61+
6262 To solve those, it should be edited to :
63-
63+
6464 # . Close the file using `sw.Close()`,
6565 # . Be wrapped inside a `try`…`catch` block,
6666 # . Either test first if the file exists, or use the `StreamWriter` constructor that appends to the file if it already exists.
You can’t perform that action at this time.
0 commit comments