java read file cannot find file

java read file cannot find file

the file test.txt and the file Lautturi.class must be in the same directory:

/**
 * @author lautturi.com
 * Java example: cannot find file while reading text file
 */
import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(Lautturi.class.getResourceAsStream("test.txt"));

		while (scanner.hasNextLine()) {
			String line = scanner.nextLine();
			System.out.println(line);
		}
		scanner.close();

	}
}
Sour‮al.www:ec‬utturi.com

output:

The first line
The second line
Created Time:2017-09-19 15:18:04  Author:lautturi