Skip to content

Instantly share code, notes, and snippets.

@ekirastogi
Created November 11, 2015 17:04
Show Gist options
  • Save ekirastogi/59d33ab7d50e21cd64d0 to your computer and use it in GitHub Desktop.
Save ekirastogi/59d33ab7d50e21cd64d0 to your computer and use it in GitHub Desktop.
How to create a File in Java using FileWriter
package com.ekiras.demo;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
class FileDemo {
public static void main(String args[]) {
readFile();
}
public static void readFile() {
System.out.println(" Start :: writing file");
try {
File file = new File("/home/ekansh/myFile.txt");
FileWriter fileWriter = new FileWriter(file);
fileWriter.write("hello, this file is created at :: " + new Date());
fileWriter.flush();
fileWriter.close();
System.out.println(" End :: writing file");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment