![]() If we run the program from command line, for the non-absolute path, File object tries to locate files from the current directory. ![]() For a non-absolute path, File object tries to locate files in the project root directory. When we create the File object by passing the file name, it can be with absolute path, or we can only provide the file name or we can provide the relative path. The files created is empty and of zero bytes. This method also throws java.io.IOException when it’s not able to create the file. File createNewFile() method returns true if new file is created and false if file already exists. When we initialize File object, we provide the file name and then we can call createNewFile() method to create new file in Java. Java.io.File class can be used to create a new File in Java. There are three popular methods to create file in java. Today we will look into different ways to create a file in java. Creating a file is a very common IO operation.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |