<div style='background-color: none transparent;'></div>
Home » » Java write to file line by line

Java write to file line by line

import java.io.*;

class FileWrite {
public static void writeToFile(String text) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(
"C:/new.txt"), true));
bw.write(text);
bw.newLine();
bw.close();
} catch (Exception e) {
}
}

public static void main(String[] args) throws Exception {
String st1 = "Hello";
String st2 = "Where there is will, there is a way";

writeToFile(st1);
writeToFile(st2);

System.out.println("File created successfully!");
}
}
Share this article :
 
Copyright © 2011. B.Sc B.Tech MCA Ploytechnic Mini,Main Projects | Free Main Projcets Download | MCA |B.tech . All Rights Reserved
Company Info | Contact Us | Privacy policy | Term of use | Widget | Advertise with Us | Site map
Template Modify by Creating Website. Inpire by Darkmatter Rockettheme Proudly powered by Blogger