0

My code is follows:

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

public class Movies {
    public String rFile() {
        try {
            Scanner file = new Scanner(new File("./file.txt"));
            while(file.hasNextLine()) {
                System.out.println(file.nextLine());
            }
        } catch (FileNotFoundException e) {
            System.out.println("File not found!");
        }
        return "";
    }
    
    public static void main(String[] args) {
        Movies movies = new Movies();
        movies.rFile();
    }
}

My file.txt file is as below: 1994 The Shawshank Redemption 1972 The Godfather 1974 The Godfather: Part II

The output is as below: 1994 The Shawshank Redemption 1972 The Godfather 1974 The Godfather: Part II

I don't know why it is printing those characters at the begining.

Chetan
  • 387
  • 1
  • 4
  • 11
  • 2
    I suspect your file *actually* starts with a [UTF-8 Byte Order Mark](https://en.wikipedia.org/wiki/BOM). You could see this if you use a binary file viewer. – Jon Skeet Dec 04 '21 at 08:29
  • Yes you are right I see EF, BB, BF bytes in the beginning when I view in binary file viewer. – Chetan Dec 04 '21 at 08:37

0 Answers0