import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Scanner;
public class Fileread {
public static void main(String args[])throws Exception{
//create a file
File myObj = new File("D:\\filename1.txt");
if (myObj.createNewFile())
{
System.out.println("File created: " + myObj.getName());
}
else
{
System.out.println("File already exists.");
}
//copy the file from one location to another
FileWriter myWriter = new FileWriter("D:\\filename1.txt");
myWriter.write("CSIT is technology");
myWriter.close();
System.out.println("Successfully wrote to the file.");
FileReader fr=new FileReader("D:\\filename1.txt");
FileWriter fw=new FileWriter("D:\\RRR.txt");
int i;
while((i=fr.read())!=-1)
fw.write((char)i);
//append or update the content of the file
Scanner s=new Scanner(System.in);
String data=s.nextLine();
BufferedWriter bw = new BufferedWriter(fw);
bw.write(data);
System.out.print("Enter the Name of File to Delete: ");
String filename = s.nextLine();
//delete the file
File myfile = new File(filename);
if(myfile.delete())
System.out.println("\nThe file is deleted successfully!");
else
System.out.println("\nSomething went wrong!");
bw.close();
fr.close();
fw.close();
}
}