In this problem we learn how to create a text file in Java. This file will be empty and created if their is no file with that name already exist. If file exist already the error message will be display else program execute successfully with the message your file is created.
Source Code
package www.ancodingpoint.com; import java.io.File; public class Creating_File { public static void main(String[] args) { try { File f = new File (" ancodingpoint.txt "); if (f.createNewFile()) System.out.println(" Your File is Created! "); else System.out.print(" File Already Exist "); } catch (Exception e) { System.out.println(" Error found "); } } }
0 comments:
Post a Comment