Thursday, 28 July 2016

Java Tutorial : Java IO (FileReader class)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=funrSahvWE4&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java IO (FileReader class) 
Java Tutorial : Java IO (FileReader class) 
Java Tutorial : Java IO (FileReader class) 
Java Tutorial : Java IO (FileReader class) 
Java Tutorial : Java IO (FileReader class) 
myfile.txt
Peter is coming to India. 
FileReaderDemo.java
import java.io.FileReader;
import java.io.IOException;

/*
 * public FileReader(String fileName) throws
 *                           FileNotFoundException
 * 
 * Parameters:
 * ----------
 * 
 * fileName - the name of the file to read from
 */
public class FileReaderDemo
{

    public static void main(String[] args) throws IOException
    {
        FileReaderDemo fileReaderDemo = new FileReaderDemo();
        fileReaderDemo.readFile();
    }

    private void readFile() throws IOException
    {
        FileReader fileReader = null;

        try
        {

            /*
             * Creates a new FileReader, given the name of
             * the file to read from.
             */
            String fileName = "myfile.txt";
            fileReader = new FileReader(fileName);
            int i;

            /*
             * Reads a single character or -1 if the end of
             * the stream has been reached
             */
            while ((i = fileReader.read()) != -1)
            {
                System.out.print((char) i);
            }
        }
        finally
        {
            if (fileReader != null)
            {
                /*
                 * Closes the stream and releases any system
                 * resources associated with it. Once the
                 * stream has been closed, further read(),
                 * ready(), mark(), reset(), or skip()
                 * invocations will throw an IOException.
                 * Closing a previously closed stream has no
                 * effect.
                 */
                fileReader.close();
            }
        }
    }

}
Output
Peter is coming to India.

Refer: 
https://docs.oracle.com/javase/8/docs/api/index.html?java/io/FileReader.html

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_FileReader_Intro_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_FileReader_Intro_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/a5a29c88719d4853b7ba8bae1b5fc9715fbc328c/BasicJava/JavaIODemo_FileReader_Intro_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge