Using FileWriter:
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- public class WriteByFileWriter {
- public static void main(String[] args) throws IOException {
- File file = new File("D:\\data1.txt");
- FileWriter contacts = new FileWriter(file);
- contacts.write("suresh - 9999999999\n");
- contacts.write("ritesh - 0000000000\n");
- contacts.write("mahesh - 8888888888");
- contacts.close();
- }
- }
Output:
suresh - 9999999999
ritesh - 0000000000
mahesh - 8888888888
No comments:
Post a Comment