Last active
January 27, 2017 10:16
-
-
Save shangeethsivan/9c7bb89bd79f2b63f99fabf73bf2992c to your computer and use it in GitHub Desktop.
File Operation in Java Writing data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File f=new File("C://new.txt"); | |
FileWriter fw=null; | |
BufferedWriter bw=null; | |
String data="Data to be stored in new.txt"; | |
if(!f.exists()){ | |
try{ | |
f.createNewFile(); | |
} | |
catch(Exception e){ | |
System.out.println(e.getMessage()); | |
} | |
} | |
try{ | |
fw=new FileWriter(f.getAbsoluteFile(),true); // Appending data | |
bw=new BufferedWriter(fw); | |
bw.write(data); | |
} | |
catch(Exception e){ | |
System.out.println(e.getMessage()); | |
} | |
finally{ | |
if(fw!=null){ | |
fw.close(); | |
} | |
if(bw!=null){ | |
bw.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment