As we are handling input and output of data, the programs written for I/O may throw IOException.
We can create Text File as well as Binary File using Java.
To create and write data in Text File, following program will be the solution:
public static void main(String[] args) {
File file=new File("Student.txt");
try {
PrintWriter out=new PrintWriter(file);
out.println("Henry Lee");
out.println(55);
out.close();
}catch(IOException e) {
System.out.println("Exception is: "+e);
}
We can create Binary File by using FileOutputStream Class:
public static void main(String[] args) {
try{
FileOutputStream fo=new FileOutputStream("Employee.txt");
fo.write(97);
fo.close();
System.out.println("Information is written into the file");
}catch(Exception e){
System.out.println(e);
}