The write() Method

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

An IOException is thrown and caught by the program.

The write() Method

With FileWriter use the write() method to write characters to the file. There are several write() methods with different parameters inherited from Writer and OutputStreamWriter. The example program uses a method that writes characters from a string:

public void write(String str)  throws IOException

To output numerical results as characters use string concatenation:

int answer;
. . .

stream.write( "The answer is: " + answer) 

QUESTION 10:

What two data transformations are performed when the above statement is executed?