Program: /*In this program we are writing the data in the file.File will automatically created if there is not a file with the given name*/
import java.io.*;
public class file
{
public static void main(String ar[])
{
try
{
FileWriter fw=new FileWriter("output.txt");
PrintWriter pw=new PrintWriter(fw);
String str="Hello";
String str1="how are you";
pw.println(str);
pw.println(str1);
pw.flush();
pw.close();
fw.close();
}catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
The data will be written in the given file.
0 comments:
Post a Comment