Java Tutorials Series - Creating and Writing Text Files

We will be covering how to create and write fe lines in a text file using java code. We will make use of BufferedWriter and FileWriter classes in doing so.

Creating and Writing Text Files -

public class App {

public static void main(String[] Args) {
       File file = new File("test.txt");

       try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
       bw.write("Line one");
       bw.newLine();
       bw.write("Line two");
       bw.newLine();
       bw.write("Last line");
   }
catch(IOException e) {
System.out.println("unable to write on File"+ file.toString());
}
}
}


That's it! Stay tuned for more tutorials on Java. Happy learning!

Comments

Popular posts from this blog

Azure Tutorials Series - Azure Networking

Coforge Interview Questions | Automation Testing profile

Testing in CI/CD