Stream and writers 1

PHOTO EMBED

Wed May 29 2024 09:14:55 GMT+0000 (Coordinated Universal Time)

Saved by @exam123

**Main.java**

import java.io.*;
import java.util.Scanner;
 public class Main {
public static void main(String[] args) {
 try {
Scanner scanner = new Scanner(System.in);
// Get airport details from the user
 System.out.println("Enter the name of the airport:");
String name = scanner.nextLine();
System.out.println("Enter the city name:");
String cityName = scanner.nextLine();
System.out.println("Enter the country code:");
 String countryCode = scanner.nextLine();
 // Write airport details to a CSV file
 FileWriter writer = new FileWriter("airport.csv");
writer.write(name + "," + cityName + "," + countryCode);
writer.close();
System.out.println("Airport details have been written to airport.csv successfully.");
 }
catch (IOException e) {
System.out.println("An error occurred while writing to the file.");
 e.printStackTrace();
}
 }
}   
content_copyCOPY