In this tutorial, you will learn how to Write Char by Char into a File in java. To understand it better, you may want to check the following first:
Java Program to Write Char by Char into a File
//write char by char into a file in java
import java.io.*;
public class FileByChar
{
public static void main(String[] args) throws IOException
{
File f=new File("javaCode.txt"); //Creation of File Descriptor for output file
FileWriter fw=new FileWriter(f); //Creation of File Writer object
fw.write('S'); //Write character by Character
fw.write('i');
fw.write('m');
fw.write('p');
fw.write('l');
fw.write('e');
fw.write('2');
fw.write('C');
fw.write('o');
fw.write('d');
fw.write('e');
fw.flush();
fw.close();
System.out.println("Check the javaCode.txt file");
}
}
Output:
Check the javaCode.txt file
Open javaCode.txt file that will be created after execution of a program
javaCode.txt
Simple2Code