Help with a loop
Could a kind Java code expert take a look at a method for me?
It seems that once called, the method starts out good by
creating/opening up a file (appending existing files). It hiccups
when it gets to the do loop. It asks the first question, then without
waiting for data to be entered, it asks the second question. This
only happens on the first iteration of the loop.
public void writeRecord()
{
PrintWriter outputStream = null;
System.out.println("This program will allow you to
enter a doctors Name,");
System.out.println("Specialty, and Fee while saving");
System.out.println("all data to a file");
System.out.println("");
System.out.println("Please enter the filename you want
to save data to.");
Scanner keyboard = new Scanner(System.in);
String fileName = keyboard.next();
try
{
//creates an object of the class
FileOutputStream
outputStream = new PrintWriter(new
FileOutputStream(fileName, true));
}
catch(FileNotFoundException e)
{
System.out.println("Error opening the file
docFile.txt.");
System.exit(0);
}
String chkLine = null;
String line = null;
do
{
System.out.println("");
System.out.println("Please enter Doctors
name:");
line = keyboard.nextLine();
outputStream.println(line);
System.out.println("");
System.out.println("Please enter Specialty:");
line = keyboard.nextLine();
outputStream.println(line);
System.out.println("");
System.out.println("Please enter Fee:");
line = keyboard.nextLine();
outputStream.println(line);
System.out.println("");
System.out.println("Continue entering data?
\"y\" or \"n\"");
line = keyboard.nextLine();
chkLine = line;
}
while(! chkLine.equalsIgnoreCase("n"));
outputStream.close();
System.out.println("done");