Advertisement
thenewboston

Java Programming Tutorial - 80 - Writing to Files

Aug 22nd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Formatter;
  2.  
  3. class CreateFiles {
  4.    public static void main(String args[ ]) {
  5.       Create f = new Create();
  6.       f.openFile();
  7.       f.recordFile();
  8.       f.closeFile();
  9.    }
  10. }
  11.  
  12. class Create {
  13.    private Formatter f;
  14.    
  15.    void openFile() {
  16.       try {
  17.          f = new Formatter("U1.txt");
  18.       } catch(Exception e) {
  19.          System.out.println("You have an error");  
  20.       }
  21.    }
  22.    
  23.    void recordFile() {
  24.       f.format("%s %s %s", "Mr", "Somebody", "20");  
  25.    }
  26.    
  27.    void closeFile() {
  28.       f.close();  
  29.    }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement