Experiment-8 Abhishek Choudhary 07311503113 AIM
Experiment-8 Abhishek Choudhary 07311503113 AIM
Experiment-8 Abhishek Choudhary 07311503113 AIM
ABHISHEK CHOUDHARY
07311503113
AIM
File Handling
(A)To write content into a file
(B)To read content of a file
(C)To copy content of one file into another file
(A) SOURCE CODE
import java.io.*;
class write_ch
{
public static void main(String args[])
{
File outfile=new File("Demo.txt");
FileWriter fw=null;
try
{
fw=new FileWriter(outfile);
int ch;
String s="Happiness is when what you think,what you say and what you do are
in harmony";
fw.write(s);
}
catch(IOException ie)
{
ie.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
fw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
OUTPUT
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
OUTPUT
finally
{
try
{
fr.close();
fw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
OUTPUT