Skip to content

Instantly share code, notes, and snippets.

@shangeethsivan
Last active January 27, 2017 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shangeethsivan/9c7bb89bd79f2b63f99fabf73bf2992c to your computer and use it in GitHub Desktop.
Save shangeethsivan/9c7bb89bd79f2b63f99fabf73bf2992c to your computer and use it in GitHub Desktop.
File Operation in Java Writing data
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