954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

java file reader

Hello guys! I just want to ask if how can I use java file reader? I badly need this for my program...

Thank you in advance!

:)

vin24
Newbie Poster
23 posts since Sep 2010
Reputation Points: 10
Solved Threads: 3
 

maybe this help

import java.io.*;

public class ReadFile {

  public static void main(String[] args) {

    File file = new File("C:\\sample_text.txt");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    try {
      fis = new FileInputStream(file);

      // Here BufferedInputStream is added for fast reading.
      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);

      // dis.available() returns 0 if the file does not have more lines.
      while (dis.available() != 0) {

      // this statement reads the line from the file and print it to
        // the console.
        System.out.println(dis.readLine());
      }

      // dispose all the resources after using them.
      fis.close();
      bis.close();
      dis.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
codewall
Junior Poster in Training
80 posts since Dec 2010
Reputation Points: 13
Solved Threads: 11
 

If it is ok to you, please give me a sample program that uses java file reader?

vin24
Newbie Poster
23 posts since Sep 2010
Reputation Points: 10
Solved Threads: 3
 

You can check my blog...
http://codewall.blogspot.com/p/free-program.html
maybe some program and code may help you

codewall
Junior Poster in Training
80 posts since Dec 2010
Reputation Points: 13
Solved Threads: 11
 

@codewall.
Please keep in mind the Daniweb principle:
"to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well."
Just giving lazy people code to copy teaches them little or nothing (except maybe that cheating works).

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: