
808 CHAPTER 11 Exceptions and Input/Output Operations
EXERCISES,PROBLEMS, AND PROJECTS
}
catch ( IOException ioe )
{
ioe.printStackTrace();
}
30. This code sequence loops through the array grades and writes all its
elements into the file data.txt, one per line:
int []grades = { 98, 76, 82, 90, 100, 75 };
try
{
FileOutputStream fos = new FileOutputStream( ”data.txt“, false );
// your code goes here
}
// and your code continues here
31. This code sequence loops through the array grades, calculates the
average, and writes the average into the file data.txt:
int []grades = { 98, 76, 82, 90, 100, 75 };
double average = 0.0;
for ( int i = 0; i < grades.length; i++