I wrote a little program to write to a text file. This is a very simple one and I wrote it all by myself.
I thought this would be useful to a beginner in Java since this code is a very simple one.
So here goes the code.
Code: Select all
import java.util.Formatter;
import java.util.Scanner;
public class Write_To_File{
public static void main(String args[]){
try{
Formatter file = new Formatter("Output.txt");
Scanner input = new Scanner(System.in);
System.out.println();
System.out.println("Enter what you need to write to the file");
file.format("%s ", input.nextLine());
file.close();
}
catch(Exception e){}
}
}