import java.io.*;
public class App
{
public static void main(String[] args)
{
// Local variables and object references.
char again = ‘y’;
File fd;
DataOutputStream out;
// Get the path name from the user.
System.out.print(“Enter the file’s complete path name: “);
fd = new File(Keyboard.readString());
// Try to write data to the output stream.
try
{
// Open an output stream for the file.
out = new DataOutputStream(new FileOutputStream(fd));
// This loop asks the user to enter a number and writes it to the
// stream. The user is then asked if they want to enter another.
while (again == ‘Y’ || again == ‘y’) {
System.out.print(“Enter any real number (n.n): “);
double theNumber = Keyboard.readDouble();
out.writeDouble(theNumber);
System.out.print(“Again? (Y/N): “);
again = Keyboard.readChar();
}
// Close the stream.
out.close();
System.out.println(“Closed – ” + fd.getPath());
}
// Catch an IOException if one is thrown.
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
} |