How to create a file in Java

How to create a file in Java,while working with different files in Java it is very important to creating new files whether it could be any format to store the data.In this post you will learn how to create a files in java grammatically,please observe below simple example to create a file in Java.

How to create a file in Java


Also Read - Extract Number from a String


How to create a file in Java


For creating files in java you can use File.createNewFile() method is used to create a new file in Java language and which will return Boolean value means whether it is a true or false after creating the file in java.

Example:


package com.java.filescreateread;
import java.io.File;
import java.io.IOException;

public class CreateFiles {
public static void main(String[] args) throws IOException {
File file = new File("E:\\java\\Files\\Simplefiless.csv");
file.createNewFile();
if(file.isFile()){
System.out.println("New CSV file is created");
}else{
System.out.println("New CSV file is not created and already exists.");
}
}

}

Here in above code new file is created and as well as it will verify whether file is exists in created path or not.Please provide your comments on this post.

Share this :

Previous
Next Post »
0 Komentar

Penulisan markup di komentar
  • Silakan tinggalkan komentar sesuai topik. Komentar yang menyertakan link aktif, iklan, atau sejenisnya akan dihapus.
  • Untuk menyisipkan kode gunakan <i rel="code"> kode yang akan disisipkan </i>
  • Untuk menyisipkan kode panjang gunakan <i rel="pre"> kode yang akan disisipkan </i>
  • Untuk menyisipkan quote gunakan <i rel="quote"> catatan anda </i>
  • Untuk menyisipkan gambar gunakan <i rel="image"> URL gambar </i>
  • Untuk menyisipkan video gunakan [iframe] URL embed video [/iframe]
  • Kemudian parse kode tersebut pada kotak di bawah ini
  • © 2015 Simple SEO ✔