Created
November 11, 2015 17:04
-
-
Save ekirastogi/59d33ab7d50e21cd64d0 to your computer and use it in GitHub Desktop.
How to create a File in Java using FileWriter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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