Advertisement
makispaiktis

16. Create a new file and add data

May 31st, 2022 (edited)
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import javax.crypto.SecretKey;
  2. import java.io.*;
  3. import java.lang.*;
  4. import java.util.*;
  5.  
  6. public class CreateFile {
  7.  
  8.     // Variables
  9.     private Formatter x;
  10.  
  11.     // Methods
  12.     public void openFile(){
  13.         try{
  14.             x = new Formatter("Chinese.txt");
  15.         }
  16.         catch (Exception e){
  17.             System.out.println("You have got an error");
  18.         }
  19.     }
  20.  
  21.     public void addRecords(){
  22.         x.format("%s %s %s", "Name", "Surname", "22");
  23.     }
  24.  
  25.     public void closeFile(){
  26.         x.close();
  27.     }
  28.  
  29.     // Main Function
  30.     public static void main(String[] args){
  31.         CreateFile f = new CreateFile();
  32.         f.openFile();
  33.         f.addRecords();
  34.         f.closeFile();
  35.     }
  36.  
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement