A good answer might be:

Yes--the parameter for the constructor is a string, which could contain user data.

Power of Two Table

The second example program writes a table to a disk file named by the user. The trim() method removes leading and trailing spaces from the user data. Two try{} blocks are used so that if the constructor throws an exception an appropriate error message is written.

import java.io.*;
class PowerTable
{
  public static void main ( String[] args ) 
  {

    // Get filename and create the file
    FileWriter writer = null;
    BufferedReader user = new BufferedReader(
        new InputStreamReader( System.in ) );
    String fileName = "";

    System.out.print("Enter Filename-->"); System.out.flush();
    try
    {
      fileName = user.readLine().trim();
      writer = new FileWriter( fileName );
    }
    catch ( IOException iox )
    {
      System.out.println("Error in creating file");
      System.exit(0);
    }
      
    // Write out the table.
    try
    {  
      int value = 1;
      writer.write( "Power\tValue\n"  );
      for ( int pow=0; pow<=20; pow++ )
      {
        writer.write( pow + "\t" + value + "\n"  );  
        value = value*2;
      }
      writer.close();
    }
    catch ( IOException iox )
    {
      System.out.println("Problem writing " + fileName );
    }
  }
}

The string parameter of the write() method is created by converting numbers to characters and concatenating them to the string. The character '\t' is the tab character.

QUESTION 12:

(Review: ) What is a buffer?

Click Here after you have answered the question