Results 1 to 3 of 3
  1. #1
    pardhu is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default problem in displaying file contents

    AIM:PROGRAM TO READ FILE CONTENTS AND DISPLAY THEM ALONG WITH LINE NUMBERS

    i tried the following code but i didn't get the correct 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...........

  2. #2
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default Re: problem in displaying file contents

    First off, please always use [code ] [/code ] (no spaces) tags to enclose your code.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: problem in displaying file contents

    Secondly fully explain what "didn't get the correct output" means.

Similar Threads

  1. problem in displaying file contents
    By pardhu in forum New To Java
    Replies: 0
    Last Post: 10-24-2011, 04:27 PM
  2. frame not displaying correct contents
    By yemista in forum AWT / Swing
    Replies: 5
    Last Post: 10-20-2011, 06:30 PM
  3. Replies: 4
    Last Post: 10-30-2009, 11:38 PM
  4. Replies: 12
    Last Post: 10-09-2009, 07:26 AM
  5. Replies: 0
    Last Post: 07-17-2007, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •