JDoodle

Easy and Quick way to compile and run Java Code Online

Java
Version - JDK 1.8.0_66
Project Name :
Your Code ...
import java.io.*; public class MyClass { public static void main(String args[]) { String fileName = "myfile.txt"; System.out.println("Start writing...."); writeFile(fileName); System.out.println("Writing complete...."); System.out.println("Start reading...."); readFile(fileName); System.out.println("Reading complete...."); } private static void writeFile(String fileName) { try { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(fileName)); bufferedWriter.write("Hi, Writer in action, line one"); bufferedWriter.newLine(); bufferedWriter.write(" another line."); bufferedWriter.close(); } catch(IOException ex) { System.out.println("Error writing...."); } } private static void readFile(String fileName) { String txt = null; try { BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName)); while((txt = bufferedReader.readLine()) != null) { System.out.println(txt); } bufferedReader.close(); } catch(FileNotFoundException ex) { System.out.println("Unable to read..."); } catch(IOException ex) { System.out.println("Unable to read..."); } } }
External Libraries ...
Input Arguments (args of Main Method)...
Result...
compiled and executed in second(s)
Hint - Press Ctrl+Space or Alt+Space for Auto Complete.
Your valuable inputs will help us improve this site
please give your comments. Thanks.
Which language would you like to see next in JDoodle?
Comments/Suggestions/Inputs...
Please Login to use this option....