But I'm thinking I may want to read that binary file, and put the contacts into a combo box for the user to select who they would like to call. I KIND OF know how this would work, but I want to double check so I don't waste 2 days figuring this out.
1. I have to read the file in, and parse each field to a new String array
2. I have to use the String array to populate the combo box
3. Display the combo box (JDialog?), and let the user select a contact to call.
Does that sound right? Any advice?
Here is the code that creates my Contacts file:
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Contacts
{
public static void main(String[] args)
{
Contacts fileIO = new Contacts();
String lName[] = new String[3];
String fName[] = new String[3];
String phone[] = new String[3];
lName[0] = "Who";
lName[1] = "Potter";
lName[2] = "Hobbit";
lName[3] = "The Gray";
fName[0] = "Doctor";
fName[1] = "Harry";
fName[2] = "Frodo";
fName[3] = "Gandolf";
phone[0] = "(770) 335 2536";
phone[1] = "(842) 589 1111";
phone[2] = "(910) 963 2201";
phone[3] = "(770) 457 1625";
for(int i = 0; i<3; i++)
{
fileIO.Write(lName[i], fName[i], phone[i]);
}
}//END MAIN
public void Write(String lName, String fName, String phone)
{
DataOutputStream output;
output = null;
File fileOut = new File("myContacts.data");
try
{
output = new DataOutputStream(new FileOutputStream(fileOut));
}
catch(IOException i)
{System.out.println(i);}
try{ //try for write
output.writeUTF("Last Name: ");
output.writeUTF(lName);
output.writeUTF("First Name: ");
output.writeUTF(fName);
output.writeUTF("Phone: ");
output.writeUTF(phone);
}catch (IOException i)
{System.out.println("error in write");}
try{ //try for close
output.close();
}catch (IOException i)
{System.out.println("error in close");}
}
}//END CONTACTS
This post has been edited by synlight: 03 August 2012 - 11:29 AM

New Topic/Question
Reply




MultiQuote




|