1// Aim: Program to perform File Handling operations (File Writing).
2import java.io.FileWriter;
3import java.util.Scanner;
4public class FileWriting{
5 public static void main(String[] args) {
6 Scanner sc = new Scanner(System.in);
7 System.out.println("enter the file name :");
8 String fp = sc.nextLine();
9 System.out.println("enter the contend :");
10 String con = sc.nextLine();
11 try{
12 FileWriter fw = new FileWriter(fp);
13 fw.write(con);
14 System.out.println("success");
15 fw.close();
16 }catch(Exception e){
17 System.out.println("invalid file :"+e.getMessage());
18 }
19 sc.close();
20 }
21}
22