Skip to content

Instantly share code, notes, and snippets.

@atechcrew
Last active July 9, 2018 13:31
Show Gist options
  • Save atechcrew/0d223ea93eb20f6240b0ad8ca627c528 to your computer and use it in GitHub Desktop.
Save atechcrew/0d223ea93eb20f6240b0ad8ca627c528 to your computer and use it in GitHub Desktop.
Simple Java Code To Write file. Java Code To Store Data into file. Write File Using java.
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class WriteFile {
public static void main(String args[]) {
try {
/*
* Give The Path Of the File to store data. If the file is not found
* it will automatically create file with the given name at the given path.
*
* Remember to give the file extension for example fileName.txt
* */
File file_path = new File("file path");
FileWriter file_reader = new FileWriter(file_path);
BufferedWriter buff = new BufferedWriter(file_reader);
buff.write("This is the data.");
buff.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment