Using Printwriter (java.io.*)
I have a problem trying to get my program to read names from the user and store them in a file. I did some debugging and managed to narrow it down to my use of the pwStream variable, would appreciate any help on this:
/** Purpose: To learn how to use the java io package and incorporate exception handling in the program. Specifically, I am trying to get my program to request the user for 3 names, and store the names in a file called 'NAMES.txt'.
public class Test
public static void main(String  args)
PrintWriter pwStream= new PrintWriter(new BufferedWriter (new FileWriter ("NAMES.txt")));
Scanner sc=new Scanner(System.in);
System.out.println("Please enter 3 names to be stored in the file: ");
for (int i=0;i<3;i++)
pwStream.println(str); // here is where my problem is, after execution, the file NAMES.txt contains no names
catch (IOException e)
END OF CODE
Thanks for helping :)
p.s. sorry bout the indents, i cant get my program to be indented when it is published here, got to figure that one out.