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!

:)

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();
    }
  }
}

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

@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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.