Skip to main content

Posts

Showing posts with the label Reading and Writing text File in Java

Reading and Writing text File in Java

var regex = /^([a-zA-Z0-9])+([\w_\.\-]([a-zA-Z0-9])*[a-zA-Z0-9])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; Simple code to demonstrate to Read and Write text file in Java. package email; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ReadAndWriteFile { public static void main(String[] args) {   try {         String content = "This is the content to write into file";          File writeFile = new File("D:/Sample.txt");    // if file doesnt exists, then create it    if (!writeFile.exists()) {     writeFile.createNewFile();    } /**   * When we pass true as parameter to FilwWriter   * then it appends the content in file instead of overwriting the ...