Creating a file and reading its content.
The folder where the file will be crated


package ch4_package;
public class Test_This {
public static void main(String[] args) throws IOException
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(;
BufferedReader br = new BufferedReader(isr);
String file_name ="", str_text="";
Process pp = new Process();
//System.out.println("---While Loop---");
System.out.print("Please Enter a File name: ");
file_name = br.readLine();
System.out.print("Now the text to be added : ");
str_text = br.readLine();
pp.process(file_name, str_text);
catch(NumberFormatException e)
{ System.out.println("data was blank");}
class Process {
public String file_name="";
File create_file;
String show_text= "";
public void process(String str1, String str2)
try {
File file = new File(str1);
boolean success = file.createNewFile();
if (success){
file_name= file.getName();
show_text = str2;
System.out.print( "file name " + file_name);
char buff[] = new char[show_text.length()];
show_text.getChars(0,show_text.length(),buff, 0);
FileWriter fr = new FileWriter(str1);
for (int i =0; i <buff.length; i++)
} catch (IOException e) { System.out.println("could not read");



note the file is added

Reassurance of creating a file and added texts

file_name= file.getName();
show_text = str2;
System.out.print( "file name " + file_name);


and also note that the text has been added.