Skip to content

Instantly share code, notes, and snippets.

@yassaa
Created November 17, 2014 09:18
Show Gist options
  • Save yassaa/c7ac2e7227e456abe6de to your computer and use it in GitHub Desktop.
Save yassaa/c7ac2e7227e456abe6de to your computer and use it in GitHub Desktop.
Userdatabase
package test_Bookingsystem;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class UserDatabase {
//write to file
// GetUsers takes no parameter; it reads all the users from the database
public void User[] getUsers() {
try(DataOutputStream output = new DataOutputStream(new FileOutputStream("UserDatabase1.dat"))){
}
//adding catch blocks
catch (IOException ex) {
System.out.println(" .... ");
}
}
public void saveUsers(User user ){
//DataInputStream reads bytes from the stream and converts them into
//appropriate primitive-type values or strings.
try(DataInputStream input = new DataInputStream(new FileInputStream("UserDatabase1.dat"))){
System.out.println("User Name: " + input.readUTF());
System.out.println("Email: " + input.readUTF());
System.out.println("Phonenumber: " + input.readLong());
}
//adding catch blocks
catch (IOException ex) {
System.out.println("....");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment