Infolinks In Text Ads

Jun 22, 2010

How to read a file in java - code example

Java code for read a text file in java
 
File file = new File("C:\\filenamehere.txt");
    FileInputStream
fileInputStream null;
    BufferedInputStream
bufferedInputStream null;
    DataInputStream
dataInputStream null;

    try {
     
fileInputStream new FileInputStream(file);

     
     
bufferedInputStream new BufferedInputStream(fileInputStream);
     
dataInputStream new DataInputStream(bufferedInputStream);

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

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

     
     
fileInputStream.close();
     
bufferedInputStream.close();
      
dataInputStream.close();

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

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...