Java Address Book Project! Help needed!

eViLoNe

In Runtime
Messages
126
Ok,

As the title states, I'm doing a java address book project. I have the GUI all setup, and ready, and also have the class setup to model a contact. The part I'm having trouble with is the actual opening of a binary file, and saving of a binary file to store the "vectors" in, which will hold the address book information.

If anyone here could shed some light on this for me, it would be greatly appreciated.

Thanks.
 
ok, why don't you just use the jdbc odbc drivers and store the data in a database?
 
heres somthing on how to read Binary Data from a binary file its a snipplet of code:



// Read binary data from a binary file.
// The name of the input file is
// passed as a command line argument.
//
//
// Adapted from exreaddata.java from
// "Just Java", P.van der Linden, ch.12
//
import java.io.*;

public class BinFileInput {
public static void main(String f[]) {
FileInputStream fis;
DataInputStream dis;
try {
fis = new FileInputStream(f[0]);
// Wrap with a DataInputStream to obtain
// its readInt() method.
dis = new DataInputStream( fis );
System.out.println( "file: " + f[0] );

int i;

while ( true ) {
i = dis.readInt();
System.out.println( "read: " + i );
}
} catch (EOFException eof)
{System.out.println( "EOF reached " ); }
catch (IOException ioe)
{System.out.println( "IO error: " + ioe );}

}

}
 
And this is to Write Binary data to a binary file, again another snipplet:



// Write binary data to a binary file.
// The name of the output file is
// passed as a command line argument.
//
//
// Adapted from exwritedata.java from
// "Just Java", P.van der Linden, ch.12
//
import java.io.*;

public class BinFileOutput {
public static void main(String f[]) {
FileOutputStream fos;
DataOutputStream ds;
try {
fos = new FileOutputStream(f[0]);

// Wrap the FileOutputStream with a
// DataOutputStream to obtain its writeInt()
// method.
ds = new DataOutputStream( fos );

int a[] = {0,1,2,3,4,5,6,7,8,9};

for (int i=0; i<a.length; i++) {
ds.writeInt(a);
}

} catch (IOException ioe) {
System.out.println( "IO error: " + ioe ); }
}
}
 
Wow, that's the best code I've seen you do man. What site did you get it from? :p

Watch the double posting though. We have an edit button. Just because you are my friend doesn't mean I"ll go easy on you :).

As a heads up, if the file you are reading or writing to is not in the same folder, the "file name" you are reading or writing to must also include the path. IE C:\Documents and Settings\Bill_Joe_Bob\Java_stuff\email_addressbook.Java
 
Back
Top Bottom