/Users/lyon/j4p/src/addBk/addressBook/CSVExport.java

1    package addBk.addressBook; 
2     
3    import futils.Futil; 
4     
5    import java.io.*; 
6     
7     
8    public class CSVExport { 
9        static boolean isSwing = false; 
10    
11       public CSVExport(AddressBookDatabase abd) { 
12    
13           try { 
14               BufferedWriter bw = getWriter( 
15                       "select a CSV file for export"); 
16               for (int i = 0; i < 
17                               (abd.getNumRecords()); i++) { 
18                   AddressBookRecord abr = abd.readRecord( 
19                           i); 
20                   bw.write(abr.name + ","); 
21                   bw.write(abr.address + ","); 
22                   bw.write(abr.notes + ","); 
23                   bw.write(abr.dial_1 + ","); 
24                   bw.write(abr.dial_2 + ","); 
25                   bw.write(abr.dial_3 + ","); 
26                   bw.newLine(); 
27               } // end for 
28               bw.close(); 
29           } catch (FileNotFoundException e) { 
30           } catch (IOException e) { 
31           } 
32    
33       }  // end constructor 
34    
35       public static BufferedWriter getWriter( 
36               String prompt) 
37               throws FileNotFoundException, 
38                      IOException { 
39           return new BufferedWriter( 
40                   new OutputStreamWriter( 
41                           new FileOutputStream( 
42                                   Futil.getWriteFile(prompt)))); 
43       } 
44    
45    
46   } // end CSVExport 
47