/ Java

Close file handler in java while operating on files

I just bumped into one of the error with file io. if you dont close fie handler, it wont write anything into file.

import java.io.*;
class FileWrite { 
public static void main(String args[]) { 
    // Create file 
    FileWriter fstream = new FileWriter("out.txt"); 
    BufferedWriter out = new BufferedWriter(fstream); 
    out.write("Hello Java"); 
    //Close the output stream 
}catch (Exception e){
//Catch exception if any 
System.err.println("Error: " + e.getMessage());
Prashanth Madi

Prashanth Madi

I'm a programmer & Tech enthusiast. I work for Big Data Support Team at Microsoft, but this blog, its content & opinions are my own. I blog about tech, gadgets, code, where we're going & we've been.

Read More