Java Programming Tutorial - - Writing to Files




import java.io.*;
import java.lang.*;
import java.util.*; 

public class Coffee {
private Formatter x; 

public void openFile () {
try {
x= new Formatter("chinese.txt");
System.out.println("you created a file");
}
catch (Exception e) {
System.out.println("you have an error");
}
}
public void addRecords () {
x.format("%s%s%s", "20 ", "thileban ", "nagarasa");
}
public void closeFile() {
x.close(); 
}
}




class cup{
public static void main (String[] args) {
Coffee g = new Coffee (); 
g.openFile ();
g.addRecords (); 
g.closeFile ();
}
}

Comments