i have done a read() and a write()... after running write() the read() won't read the newly wrote data until i compile again. my guess is that the newly written data doesn't get saved until i compile again.. please if anyone knows how to make it saved so the read() can read everything after the write()
public static int read(Member box[])
{
Scanner reader = null;
int count =0;
try
{
reader = new Scanner(new FileReader("database.txt"));
int id;
String type, fn, ln, ph;
Double fee;
while(reader.hasNextLine())
{
id= reader.nextInt();
type= reader.next();
fn= reader.next();
ln= reader.next();
ph= reader.next();
fee= reader.nextDouble();
box[count]= new Member(id, type, fn, ln, ph, fee);
count++;
}
}
catch(FileNotFoundException e)
{
System.out.println("File not Found!");
}
catch(IOException e)
{
System.out.println("Error reading");
}
catch(NoSuchElementException e)
{
}
reader.close();
return count;
}
////////// to write data to the text file //////////////////
public static void write(int count)
{
count++;
Scanner keyboard = new Scanner(System.in);
PrintWriter writer = null;
try
{
writer = new PrintWriter(new FileOutputStream("database.txt", true));
System.out.println("Please enter for member info:");
writer.println(count);
System.out.println("What is the member's member type?");
writer.println(keyboard.next());
System.out.println("First Name:");
writer.println(keyboard.next());
System.out.println("Last Name");
writer.println(keyboard.next());
System.out.println("Phone number:");
writer.println(keyboard.next());
System.out.println("Member Fee:");
writer.println(keyboard.nextDouble());
}
catch(FileNotFoundException e)
{
System.out.println("File not found");
}
catch(IOException e)
{
System.out.println("The exception has been thrown");
}
System.out.println("Registration Done!");
writer.close();
}