Java Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.


here you can ask help for your java related problems
 
HomeLatest imagesSearchRegisterLog in

 

 java print the content of text file in the console

Go down 
AuthorMessage
Ak
Java Freak
Java Freak
Ak


Posts : 23
Join date : 2009-02-07

java print the content of text file in the console Empty
PostSubject: java print the content of text file in the console   java print the content of text file in the console EmptyTue Feb 10, 2009 3:39 am

Code:


import java.io.*;
public class textreader {

    public static void main(String args[]) throws IOException
    {
        try
        {
            //open the file
          FileInputStream fis = new FileInputStream("C:\\file.txt");

            //get the object from datainputstream
            DataInputStream dis = new DataInputStream(fis);
            BufferedReader br = new BufferedReader(new InputStreamReader(dis));
            String stringline;

            //read file line by line
        while((stringline = br.readLine()) != null)
        {
            //print the content of the file in the console
            System.out.println(stringline);
        }
            //close the datainputstream
            dis.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

}
Back to top Go down
https://javafreak.board-directory.net
 
java print the content of text file in the console
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Java Programming-
Jump to: