import java.io.*;
import javax.swing.JOptionPane;
public class sample
{
public static void main(String args[])
{
try
{
PrintWriter pw=null;
String n1,n2;
String filename="C:\\jpcezar\\out.txt";
n1=JOptionPane.showInputDialog("Enter you Name:");
n2=JOptionPane.showInputDialog("Enter you Address:");
boolean apend=true;
if(apend)
{
pw=new PrintWriter(new FileWriter(filename,true));
}
else
{
pw=new PrintWriter(new FileWriter(filename,false));
}
pw.println("My Name is:" + n1);
pw.println("My Address is:" + n2);
JOptionPane.showMessageDialog(null,"Successfully save ");
pw.close();
pw.flush();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"File not found"));
}
}
}
No comments:
Post a Comment