import java.io.*;
import java.util.Scanner;
class FileReading
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
String fname = sc.nextLine();
File file = new File(fname);
if(!file.exists()|| !file.isFile())
{
System.out.println("File not found or not a valid file");return;
}
try(BufferedReader br=new BufferedReader(new FileReader(file)))
{
String line;
int linenumber=1;
while((line=br.readLine())!=null)
{
System.out.println(linenumber+" "+line);
linenumber++;
}
}
catch(IOException e)
{
System.out.println("An error occured while reading the file: "+e.getMessage());
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: