In this example we will write to a file from user's input
 
 
 
Example

import java.io.*;
import java.util.*;
import java.text.Normalizer;
import java.text.Normalizer.Form;


public class Test_This {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str ="";//, str1="";int n1=0, n2 = 1;
Process pp = new Process();//object is created

System.out.println("Please type the contents ");
try {
str = br.readLine();
pp.method_1(str);
}
catch(IOException e)
{
System.out.println("Blank Data ");
}

}
}
class Process
{

public void method_1(String str)throws IOException
{
File file = new File("C:\\myjava\\input_output\\File\\debug.txt");
try {
PrintStream ps = new PrintStream(file);
System.setOut(ps);
} catch (IOException e) {
}
System.out.println(str);
}
}

Note: Every time the contents will be replaced with a new text.