Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileWriter;
- import java.io.BufferedWriter;
- import java.io.IOException;
- public class fileWriterExample {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try
- { // beginning of try
- String content = "computer science is cool ";
- File file = new File("C:\\Users\\Oona\\My Documents\\dataFileExample.txt");
- if(!file.exists())
- {
- file.createNewFile();
- }
- FileWriter fw = new FileWriter(file,true);
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(content);
- bw.close();
- System.out.println("Data successfully appended at the end of file");
- } // end of try
- catch(IOException ioe)
- {
- System.out.println("Exception occurred:");
- }
- } //class ends
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement