Find the error(s) in the following code, which is supposed to read a line from some- file.txt, convert the line to uppercase, then append it to somefile.txt.
```
1 String file = "someFile.txt";
2 String contents;
3
4 File someFile = new File( file );
5 FileReader inputFile = new FileReader( someFile );
6 BufferedReader input = new BufferedReader( inputFile );
7
8 contents = input.readLine();
9
10 contents = contents.toUpperCase();
11
12 input.close();
13
14 FileWriter outputFile = new FileWriter( someFile, false );
15 PrintWriter output = new PrintWriter( outputFile );
16
17 output.println( contents );
18 output.close();
```
There are two problems with the code above. The first is that the FileWriter is passed a second argument of false, so any new data written to someFile.txt will overwrite previous data. The other problem is that the code above must be placed within a try block, with a corresponding catch block, in case an IOException is thrown.
```
1 String file = "somefile.txt";
2 String contents;
3
4 try
5 {
6 File someFile = new File( file );
7 FileReader inputFile = new FileReader( someFile );
8 BufferedReader input = new BufferedReader( inputFile );
9
10 contents = input.readLine();
11
12 contents = contents.toUpperCase();
13
14 input.close();
15
16 FileWriter outputFile = new FileWriter( someFile, true );
17 PrintWriter output = new PrintWriter( outputFile );
18
19 output.println( contents );
20 output.close();
21 }
22 catch( IOException exception )
23 {
24 JOptionPane.showMessageDialog( this, "IOException occured." );
25 }
```
You might also like to view...
When adding borders and background shading to elements of an entire page, it is easiest to use the Shading and Borders buttons on the Table Styles tab.
Answer the following statement true (T) or false (F)
If you believe your server room has been experiencing problems with electricity, such as having the power turned off overnight or during weekends, connect a(n) _______________ to the power source in the equipment room to record changes in the voltage.
Fill in the blank(s) with the appropriate word(s).
In accordance with the Fair Credit Reporting Act ("FCRA"), a consumer is entitled to a free copy of his credit report if he requests the report within how many days after an adverse action?
A.30 days B.45 days C.60 days D.120 days
Which type of addresses are composed of a valid 64-bit unicast address prefix and an IPv4 interface identifier?
A. ISATAP B. Teredo C. 6to4 D. MAC