I am new to Java File Handling and I am planning to make a switch case in which the user will have to Press 1: to Create a File, Press 2: To Find the Created File and Write the File, and Press 3: To Display the file to the console. This is my practiced code, I am stuck with finding the file, I have no idea what to do anymore, here is my code. I am Stuck with Case 2.
switch(pickaNum) { case 1: // Create a File Scanner input = new Scanner(System.in); System.out.println("Enter the Name of the File You Want to Create: "); String fileName; fileName = input.nextLine(); fileName = fileName + ".txt"; File file = new File(fileName); file.createNewFile(); System.exit(0);
break;
case 2: // Find and Write Text
//String text;
Scanner sc1 = new Scanner(System.in);
System.out.println("Name of the File you Want to Write? ");
String name = sc1.nextLine();
System.out.println("Please Write Text(s) Here: ");
String text = sc1.nextLine();
name = text;
FileWriter fw = new FileWriter(name);
fw.write(name);
fw.close();
break;
case 3: