Program to Write to a file
/* * FileOutputDemo * Using PrintStream classes * */
/* This program writes a given string to file named output.txt */
import java.io.*;
class FileOutputDemo
{
public static void main(String args[])
{
String a = "phanindra";
try {
FileOutputStream out = new FileOutputStream("output.txt");
PrintStream p = new PrintStream( out );
p.println (a);
p.close();
}
catch (Exception e) {
System.err.println ("Error writing to file");
}
}
}
/* This program writes a given string to file named output.txt */
import java.io.*;
class FileOutputDemo
{
public static void main(String args[])
{
String a = "phanindra";
try {
FileOutputStream out = new FileOutputStream("output.txt");
PrintStream p = new PrintStream( out );
p.println (a);
p.close();
}
catch (Exception e) {
System.err.println ("Error writing to file");
}
}
}