الرجوع
تسجيل الدخول

What does the following code do?

import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Quiz2 {
    public static void main(String[] args) {
        String fileName = "Computer.txt";
        PrintWriter outputStream = null;
        try {
            outputStream = new PrintWriter(fileName);
        } catch (FileNotFoundException e) {
            System.out.println("Error opening the file " + fileName);
            System.exit(0);
        }
        System.out.println("Enter the text you want to write:");
        Scanner keyboard = new Scanner(System.in);
        for (int count = 1; count <= 2; count++) {
            String line = keyboard.nextLine();
            outputStream.println(count + " " + line);
        }
        outputStream.close();
        System.out.println("Those lines were written to " + fileName);
    }
}