File Write
// File handling in java
// Read from console and write to file
import java.io.*;
class FileWrite
{
public static void main(String as[]) throws IOException
{
FileWriter fout = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = "";
int i = 0;
try
{
fout = new FileWriter("opt.txt");
while(i<=3)
{
s = br.readLine();
fout.write(s+"\n");
i+=1;
}
System.out.println("File written successfully.");
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
if(fout!=null)
fout.close();
System.out.println("End of pgm.");
}
}
}
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu