
Write a Java program to accept a file name as command line argument. Append the string "File Modified by Programme" to the end of the same file and print the contents of the modified File.

import java.io.*;
import java.util.*;
class FileModifiedExample
{
public static void main(String[] args)
{
try{
Scanner input=new Scanner(System.in);
System.out.print("Enter file name: ");
String filename=input.nextLine();
FileWriter fw=new FileWriter(new File(filename),true);
BufferedWriter bw=new BufferedWriter(fw);
bw.write("File Modified by Programme");
bw.close();
System.out.println("File content is: ");
BufferedReader br=new BufferedReader(new FileReader(filename));
String line="";
while((line=br.readLine())!=null){
System.out.println(line);
}
}
catch(Exception e){
System.out.println(e);
}
}
}