View Single Post
  #2 (permalink)  
Old 03-18-2008
mira mira is offline
Jr. Member
 
Join Date: Mar 2008
Posts: 263
BRL$: -20.73
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 35
mira is on a distinguished road
Default Re: How to read text file?

You can read text file using java here is a code

HTML Code:
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInput {

  public static void main(String[] args) {

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

    try {
      fis = new FileInputStream(file);

      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);

      while (dis.available() != 0) {

        System.out.println(dis.readLine());
      }

      fis.close();
      bis.close();
      dis.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}


Current Promotions... Post a New Thread anywhere on Web Development Board to earn BRL$ 5 for every thread. Post a new Reply there and earn BRL$ 3 for every reply.
Important - Read before posting Please carefully read the Global Rules and Posting Rules for GPT / Buy - Sell Offers / Link Exchange sections before posting.
Reply With Quote