Java Week4(B) Notepad

469 views
424 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
469
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java Week4(B) Notepad

  1. 1. JAVA WEEK4(B) /* Week 4 : b) Write a Java program that reads a file and displays the file on the screen, with a line number before each line. */ import java.io.*; import java.util.*; public class LabPro9 { public static void main(String args[]) { try { FileInputStream f=new FileInputStream("run"); LineNumberReader lr=new LineNumberReader(new InputStreamReader(f)); String data; while((data=lr.readLine())!=null) { System.out.println(lr.getLineNumber()+":"+data); } System.out.println("total lines"+lr.getLineNumber()); f.close(); } catch(Exception e) {System.out.println("err"+e);} } } Page 1

×