Write a Java program that reads a file and displays the file on the screen with a line number before each line


Write a Java program that reads a file and displays the file on the screen with a line number before each line
 
                            Week – 4
 
b)Aim: To Write a Java program that reads a file and displays the file on the screen with a line number before each line.
Source Code:
 
import java.io.*;
class linenum
{
           public static void main(String[] args)throws IOException
           {
                  FileInputStream fil;
                  LineNumberInputStream line;
                  int i;
                  try
                  {
                  fil=new FileInputStream(args[0]);
                  line=new LineNumberInputStream(fil);
                  }
                  catch(FileNotFoundException e)
                  {
                  System.out.println(“No such file found”);
                  return;
                  }
                  do
                  {
                  i=line.read();
                  if(i==’n’)
                  {
                                                                                                                                            System.out.println();
                                                                                                                                                       System.out.print(line.getLineNumber()+” “);
                  }
           else
                  System.out.print((char)i);
                  }while(i!=-1);
                  fil.close();
                  line.close();
           }
}
 
Expected Output:
 
Demo.java
class Demo
1 {
2         public static void main(java Demo beta gamma delta)
3 {
4 int n = 1 ;
5 System.out.println(“The word is ” + args[ n ] );
6 }
7 }
8 ?

Write a Java program that reads a file and displays the file on the screen with a line number before each line

( java read file screen line number algorithm source code )

https://en.wikipedia.org/wiki/Command-line_interface

Have any Question or Comment?

12 comments on “Write a Java program that reads a file and displays the file on the screen with a line number before each line

Thank you for the report.
Best regards,
Boswell Zacho

Reply

[…] Write a Java program that reads a file and displays the file on the screen with a line number before… […]

[…] Write a Java program that reads a file and displays the file on the screen with a line number before… […]

[…] k=20; do { System.out.println(k); k++; } while(k!=60); } } Missing Number in java with example Write a Java program that reads a file and displays the file on the screen with a line number before… Java program to make frequency count of vowels, consonants, special symbols, digits, words in a […]

[…] { System.out.println(“Hello World”); } } Missing Number in java with example Write a Java program that reads a file and displays the file on the screen with a line number before… Java program to make frequency count of vowels, consonants, special symbols, digits, words in a […]

[…] } } } Output: Fibonacci series of 7 numbers: 0 1 1 2 3 5 8 Missing Number in java with example Write a Java program that reads a file and displays the file on the screen with a line number before… Java program to make frequency count of vowels, consonants, special symbols, digits, words in a […]

[…] {  System.out.println(“odd no are”+a[i]); } } } } Missing Number in java with example Write a Java program that reads a file and displays the file on the screen with a line number before… Java program to make frequency count of vowels, consonants, special symbols, digits, words in a […]

[…] System.out.println(“Area of rectangle:”+Rec); } } Missing Number in java with example Write a Java program that reads a file and displays the file on the screen with a line number before… Java program to make frequency count of vowels, consonants, special symbols, digits, words in a […]

[…] Write a Java program that reads a file and displays the file on the screen with a line number before… […]

[…] c=a+b; System.out.println(“sum of c:”+c); } } Missing Number in java with example Write a Java program that reads a file and displays the file on the screen with a line number before… Java program to make frequency count of vowels, consonants, special symbols, digits, words in a […]

buy generic viagra

online viagra

viagra from canada

viagra dosage 40 mg

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories