Advertisement
makispaiktis

15. Create an empty file

May 31st, 2022 (edited)
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class App {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         final Formatter x;      // It outputs a string
  8.         try{
  9.             x = new Formatter("Fred.txt");
  10.             // If it doesn't exist, it will automatically create a new file with this name
  11.             System.out.println("You created a file!");
  12.         }
  13.         catch (Exception e){
  14.             System.out.println("You have got an error");
  15.         }
  16.        
  17.     }
  18.  
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement