Results 1 to 1 of 1
- 10-24-2011, 03:27 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 16
- Rep Power
- 0
problem in displaying file contents
AIM:PROGRAM TO READ FILE CONTENTS AND DISPLAY THEM ALONG WITH LINE NUMBERS.
i tried the following code but unable to get the right output :
import java.io.*;
class file_display
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter file name");
String name=dis.readLine();
FileOutputStream fout=new FileOutputStream(name);
System.out.println("enter text & '@' to end");
char ch;
while((ch=(char)dis.read())!='@')
fout.write(ch);
fout.close();
System.out.println("entered data is : ");
FileInputStream fin=new FileInputStream(name);
int i=1,c,l=0,w=0,cc=0;
System.out.print(i);
while((c=fin.read())!=-1)
if(c=='\n')
System.out.print(++i);
System.out.print((char)c);
fin.close();
}
}
plz help me getting the correct output.....
Similar Threads
-
frame not displaying correct contents
By yemista in forum AWT / SwingReplies: 5Last Post: 10-20-2011, 05:30 PM -
Frame contents not displaying when called from elsewhere
By LoupGarou in forum AWT / SwingReplies: 4Last Post: 10-30-2009, 10:38 PM -
Problem with painting the contents of a file on a JTextArea
By Willi in forum AWT / SwingReplies: 12Last Post: 10-09-2009, 06:26 AM -
problem trying to display the contents of a text file in JTextArea
By warship in forum New To JavaReplies: 17Last Post: 07-13-2009, 05:44 AM -
problem trying to view the contents of a text file in JTextArea
By warship in forum AWT / SwingReplies: 0Last Post: 07-17-2007, 03:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks