Results 1 to 3 of 3
  1. #1
    GraemeH is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default File Reading Explanation

    Hello Everyone,

    i'm having problems understanding the following section of code:

    Java Code:
    int returnVal = fc.showOpenDialog(FileChooser.this); //...then open the file chooser box.
                if (returnVal == JFileChooser.APPROVE_OPTION)
                {
                	File file = fc.getSelectedFile(); //Get the file selected by the user.
                    
                    FileInputStream fis = null;
                    BufferedInputStream bis = null;
                    DataInputStream dis = null;
                    
                    try
                    {
                    	fis = new FileInputStream(file);
                    	
                    	bis = new BufferedInputStream(fis);
                    	dis = new DataInputStream(bis);
    would anybody be able to explain this to me please?

    So far i've got that it reads the file line by line in the form of DataInputStream. But why are the FileInputStream and BufferedInputStream needed?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, do you know the difference of the following.

    1. FileInputStream
    2. BufferedInputStream
    3. DataInputStream


    Just read about those things first of all, then you can find the solution. Read carefully about the usage of each.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Reading a doc file
    By thehero in forum Advanced Java
    Replies: 0
    Last Post: 03-15-2009, 07:48 AM
  2. Help for reading a doc file
    By thehero in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 07:44 AM
  3. Right use of file reading ?
    By jurka in forum New To Java
    Replies: 3
    Last Post: 08-27-2008, 09:16 PM
  4. need a little explanation
    By cew27 in forum New To Java
    Replies: 7
    Last Post: 12-14-2007, 12:39 AM
  5. Reading from a file
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 01:02 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
  •