Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Demonstration of how to create, read from, write and append to text files, using a menu-based approach.
- *
- * @author (Ruari Mears)
- * @version (04.01.2021)
- */
- public class ReadWriteAppendToTxtFile
- {
- private Scanner scanner = new Scanner(System.in);
- private FileHandler fileHandler = new FileHandler();
- public static void main(String[] args){
- ReadWriteAppendToTxtFile topic06 = new ReadWriteAppendToTxtFile();
- topic06.menu();
- }
- private void menu(){
- System.out.println("1\t Create a text file");
- System.out.println("2\t Read from text file");
- System.out.println("3\t Write to file");
- System.out.println("4\t Append to file");
- System.out.println();
- System.out.println("Please enter your choice:");
- int choice = scanner.nextInt();
- switch (choice) {
- case 1:
- System.out.println("Creating text file...");
- fileHandler.createFile();
- break;
- case 2:
- System.out.println("Reading from text file...");
- fileHandler.readFromFile();
- break;
- case 3:
- System.out.println("Writing to text file...");
- fileHandler.writeToFile();
- break;
- case 4:
- System.out.println("Appending to text file...");
- fileHandler.appendToFile();
- break;
- default: System.out.println("Invalid choice");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement