الرجوع
تسجيل الدخول
أنت تتصفح نسخة مؤرشفة من الموقع اضغط للانتقال إلى الموقع الجديد بكامل المزايا

Assuming "myfile.txt" does not exist in the directory where the code is run, what will be the output?

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

public class ReadFromFile {
    public static void main(String[] args) {
        String fileName = "myfile.txt";
        try {
            Scanner fileReader = new Scanner(new File(fileName));
            while(fileReader.hasNextLine()) {
                System.out.println(fileReader.nextLine());
            }
            fileReader.close();
        } catch (FileNotFoundException e) {
            System.out.println("File not found: " + fileName);
        }
    }
}