Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem in File Reading...

  1. #1
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Problem in File Reading...

    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author Shahzads
     */
    public class assignment {
     
        public static void main(String[] args) throws IOException{
        String[] key_Words=new String[11];
        key_Words[0]="int";
        key_Words[1]="long";
        key_Words[2]="public";
        key_Words[3]="static";
        key_Words[4]="void";
        key_Words[5]="main";
        key_Words[6]="print";
        key_Words[7]="println";
        key_Words[8]="System";
        key_Words[9]="out";
        key_Words[10]="class";
        BufferedReader b_R=new BufferedReader(new InputStreamReader(System.in));
        String file_Name=null;
                // file_Name = b_R.readLine();
     
                file_Name="D:\\a.txt";       
     
                File file=new File(file_Name);
                FileInputStream f_IS=new FileInputStream(file);
                BufferedInputStream b_IS=new BufferedInputStream(f_IS);
                DataInputStream d_IS=new DataInputStream(b_IS);
                while(d_IS.available()!=0){
                String line=b_R.readLine();
                System.out.println(line);
                }
                d_IS.close();
                b_IS.close();
                f_IS.close();
                /*while(line!=null){
                System.out.println(line);
                line=b_R.readLine();
                }*/
     
     
     
        }
     
    }

    I want to read the file but i don't know why it's not reading the first line. Can any of you suggest me, where to look exactly.... Thanks for reading the post.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Problem in File Reading...

    SOLVED.
    Inside loop it should be d_IS.readLine();

Similar Threads

  1. Need help with reading from .dat file
    By cyoung in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 26th, 2011, 07:34 AM
  2. Problem reading correctly from a file
    By stavrakas in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 6th, 2011, 08:09 AM
  3. Problem in reading image file
    By ramhanuman in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 3rd, 2011, 02:46 PM
  4. Reading file
    By nasi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 3rd, 2010, 03:14 AM
  5. Problem on reading file in Java program
    By nathanernest in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: April 13th, 2009, 08:14 AM