Java Tutorial : Java IO (Java File | Java File Class)


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

Click the below Image to Enlarge
Java Tutorial : Java IO (Java File | Java File Class) 
Java Tutorial : Java IO (Java File | Java File Class) 
Java Tutorial : Java IO (Java File | Java File Class) 
Java Tutorial : Java IO (Java File | Java File Class) 
Java Tutorial : Java IO (Java File | Java File Class) 
Java Tutorial : Java IO (Java File | Java File Class) 
Refer: 
https://docs.oracle.com/javase/8/docs/api/index.html?java/io/File.html
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
  • Java Tutorial : Java IO (Java PushbackInputStream-example)


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

    myfile.txt
    Hello world
    
    PushbackInputStreamDemo.java
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.PushbackInputStream;
    
    /*
     * public PushbackInputStream(InputStream in, int size)
     * 
     * Parameters:
     * -----------
     * 
     * in - the input stream from which bytes will be read.
     * size - the size of the pushback buffer.
     */
    public class PushbackInputStreamDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileInputStream fileInputStream = null;
            PushbackInputStream pushbackInputStream = null;
            try
            {
                fileInputStream = new FileInputStream("myfile.txt");
    
                /*
                 * Creates a PushbackInputStream with a pushback
                 * buffer of the specified size, and saves its
                 * argument, the input stream in, for later use.
                 */
                pushbackInputStream = new PushbackInputStream(fileInputStream, 8);
    
                byte[] byteArray = new byte[10];
                
                /*
                 * Reads up to len bytes of data from this input
                 * stream into an array of bytes.
                 */
                int numberOfBytesRead = pushbackInputStream.read(byteArray, 0, 5);
            
                System.out.println("numberOfBytesRead = "+numberOfBytesRead);
                System.out.println(new String(byteArray));
    
                /*
                 * Pushes back a portion of an array of bytes by
                 * copying it to the front of the pushback
                 * buffer.
                 */
                pushbackInputStream.unread(byteArray, 0, 5);
    
                numberOfBytesRead = pushbackInputStream.read(byteArray, 0, 5);
                System.out.println("numberOfBytesRead = "+numberOfBytesRead);
                System.out.println(new String(byteArray));
    
            }
            finally
            {
                if (pushbackInputStream != null)
                {
                    /*
                     * Closing a PushbackInputStream will also
                     * close the Reader instance from which the
                     * PushbackInputStream is reading.
                     */
                    pushbackInputStream.close();
                }
            }
        }
    
    }
    
    Output
    numberOfBytesRead = 5
    Hello
    numberOfBytesRead = 5
    Hello
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_PushbackInputStream_Example_App.rar?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/1915a31f5d5a00376375704c121f0a5c57372292/BasicJava/JavaIODemo_PushbackInputStream_Example_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
  • Java Tutorial : Java IO (Java PushbackInputStream)


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

    Click the below Image to Enlarge
    Java Tutorial : Java IO (Java PushbackInputStream) 
    Java Tutorial : Java IO (Java PushbackInputStream) 
    Java Tutorial : Java IO (Java PushbackInputStream) 
    myfile.txt
    Hello world
    
    
    PushbackInputStreamDemo.java
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.PushbackInputStream;
    
    public class PushbackInputStreamDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileInputStream fileInputStream = null;
            PushbackInputStream pushbackInputStream = null;
            try
            {
                fileInputStream = new FileInputStream("myfile.txt");
                pushbackInputStream = new PushbackInputStream(fileInputStream);
    
                /*
                 * Reads the next byte of data from this input
                 * stream.
                 */
                int data = pushbackInputStream.read();
                System.out.println((char) data);
    
                /*
                 * Pushes back a byte by copying it to the front
                 * of the pushback buffer.
                 */
                pushbackInputStream.unread(data);
    
                data = pushbackInputStream.read();
                System.out.println((char) data);
    
            }
            finally
            {
                if (pushbackInputStream != null)
                {
                    /*
                     * Closing a pushbackInputStream will also
                     * close the FileInputStream instance from
                     * which the PushbackReader is reading.
                     */
                    pushbackInputStream.close();
                }
            }
    
        }
    
    }
    
    Output
    H
    H
    
    Refer: 
    https://docs.oracle.com/javase/8/docs/api/java/io/PushbackInputStream.html
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_PushbackInputStream_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/1915a31f5d5a00376375704c121f0a5c57372292/BasicJava/JavaIODemo_PushbackInputStream_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
  • Wednesday, 19 October 2016

    Java Tutorial : Java IO (Java PushbackReader-example)


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

    myfile.txt
    Hello world
    
    PushbackReaderDemo.java
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.PushbackReader;
    
    /*
     * public PushbackReader(Reader in, int size)
     * 
     * Parameters: 
     * ---------- 
     * in - The reader from which characters will be read 
     * size - The size of the pushback buffer
     */
    public class PushbackReaderDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileReader fileReader = null;
            PushbackReader pushbackReader = null;
            try
            {
                fileReader = new FileReader("myfile.txt");
                /*
                 * Creates a new pushback reader with a pushback
                 * buffer of the given size.
                 */
                pushbackReader = new PushbackReader(fileReader, 8);
    
                char[] charArray = new char[10];
                /*
                 * Reads characters into a portion of an array.
                 */
                int numberOfCharsRead = pushbackReader.read(charArray, 0, 5);
                System.out.println("numberOfCharsRead = "+numberOfCharsRead);
                System.out.println(new String(charArray));
    
                /*
                 * Pushes back a portion of an array of
                 * characters by copying it to the front of the
                 * pushback buffer.
                 */
                pushbackReader.unread(charArray, 0, 5);
    
                numberOfCharsRead = pushbackReader.read(charArray, 0, 5);
                System.out.println("numberOfCharsRead = "+numberOfCharsRead);
                System.out.println(new String(charArray));
    
            }
            finally
            {
                if (pushbackReader != null)
                {
                    /*
                     * Closing a PushbackReader will also close
                     * the Reader instance from which the
                     * PushbackReader is reading.
                     */
                    pushbackReader.close();
                }
            }
    
        }
    
    }
    
    Output
    numberOfCharsRead = 5
    Hello
    numberOfCharsRead = 5
    Hello
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_PushbackReader_Example_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/afab0ff1466aae3a6d02c0935e804f2f099cf483/BasicJava/JavaIODemo_PushbackReader_Example_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
  • Java Tutorial : Java IO (Java PushbackReader)


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

    Click the below Image to Enlarge
    Java Tutorial : Java IO (Java PushbackReader) 
    Java Tutorial : Java IO (Java PushbackReader) 
    Java Tutorial : Java IO (Java PushbackReader) 
    myfile.txt
    Hello world
    
    PushbackReaderDemo.java
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.PushbackReader;
    
    public class PushbackReaderDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileReader fileReader = null;
            PushbackReader pushbackReader = null;
            try
            {
                fileReader = new FileReader("myfile.txt");
                pushbackReader = new PushbackReader(fileReader);
                int data = pushbackReader.read();
                System.out.println((char) data);
    
                /*
                 * Pushes back a single character by copying it
                 * to the front of the pushback buffer. After
                 * this method returns, the next character to be
                 * read will have the value (char)c.
                 */
                pushbackReader.unread(data);
    
                /*
                 * Reads a single character.
                 */
                data = pushbackReader.read();
                System.out.println((char) data);
    
            }
            finally
            {
                if (pushbackReader != null)
                {
                    /*
                     * Closing a PushbackReader will also close
                     * the Reader instance from which the
                     * PushbackReader is reading.
                     */
                    pushbackReader.close();
                }
            }
    
        }
    
    }
    
    Output
    H
    H
    
    Refer:
    https://docs.oracle.com/javase/8/docs/api/index.html?java/io/PushbackReader.html

    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_PushbackReader_App.zip?attredirects=0&d=1
    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_PushbackReader_App
    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/afab0ff1466aae3a6d02c0935e804f2f099cf483/BasicJava/JavaIODemo_PushbackReader_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
  • Java Tutorial : Java IO (Java StreamTokenizer - How to tokenize a word)


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

    StreamTokenizerDemo.java
    import java.io.IOException;
    import java.io.StreamTokenizer;
    import java.io.StringReader;
    
    public class StreamTokenizerDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            StringReader stringReader = new StringReader("Peter welcome to India");
            StreamTokenizer tokenizer = new StreamTokenizer(stringReader);
            /*
             * TT_EOL is used to determine end of line
             */
            while (tokenizer.nextToken() != StreamTokenizer.TT_EOF)
            {
                /*
                 * sval-The string value of the token, if the
                 * token was a string (word)
                 */
                System.out.println(tokenizer.sval);
            }
    
        }
    
    }
    
    Output
    Peter
    welcome
    to
    India
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_StreamTokenizerDemo_word_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/afab0ff1466aae3a6d02c0935e804f2f099cf483/BasicJava/JavaIODemo_StreamTokenizerDemo_word_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
  • Java Tutorial : Java IO (Java StreamTokenizer - How to tokenize file content)


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

    myfile.txt
    Hello, How are you peter?
    Shall we go to India. 2+2=4 
    
    StreamTokenizerDemo.java
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.StreamTokenizer;
    
    public class StreamTokenizerDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            FileReader fileReader = null;
            BufferedReader bufferedReader = null;
            try
            {
                fileReader = new FileReader("myfile.txt");
                bufferedReader = new BufferedReader(fileReader);
                StreamTokenizer st = new StreamTokenizer(bufferedReader);
    
                // print the stream tokens
                boolean eof = false;
                do
                {
                    /*
                     * Parses the next token from the input
                     * stream of this tokenizer. The type of the
                     * next token is returned in the ttype
                     * field. Additional information about the
                     * token may be in the nval field or the
                     * sval field of this tokenizer.
                     *
                     * Typical clients of this class first set
                     * up the syntax tables and then sit in a
                     * loop calling nextToken to parse
                     * successive tokens until TT_EOF is
                     * returned.
                     */
                    int token = st.nextToken();
                    switch (token)
                    {
                    case StreamTokenizer.TT_EOF:
                        System.out.println("End of File encountered.");
                        eof = true;
                        break;
                    case StreamTokenizer.TT_EOL:
                        System.out.println("End of Line encountered.");
                        System.out.println("Line Number:" + st.lineno());
                        break;
                    case StreamTokenizer.TT_WORD:
                        System.out.println("Word: " + st.sval);
                        break;
                    case StreamTokenizer.TT_NUMBER:
                        System.out.println("Number: " + st.nval);
                        break;
                    default:
                        System.out.println((char) token + " encountered.");
                        if (token == '!')
                        {
                            eof = true;
                        }
                    }
                }
                while (!eof);
            }
            finally
            {
                if (bufferedReader != null)
                {
                    bufferedReader.close();
                }
            }
    
        }
    
    }
    
    Output
    Word: Hello
    , encountered.
    Word: How
    Word: are
    Word: you
    Word: peter
    ? encountered.
    Word: Shall
    Word: we
    Word: go
    Word: to
    Word: India.
    Number: 2.0
    + encountered.
    Number: 2.0
    = encountered.
    Number: 4.0
    End of File encountered.
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_StreamTokenizerDemo_file_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/afab0ff1466aae3a6d02c0935e804f2f099cf483/BasicJava/JavaIODemo_StreamTokenizerDemo_file_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
  • Tuesday, 18 October 2016

    Java Tutorial : Java IO (Java StreamTokenizer)


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

    Click the below Image to Enlarge
    Java Tutorial : Java IO (Java StreamTokenizer) 

    Java Tutorial : Java IO (Java StreamTokenizer) 

    Java Tutorial : Java IO (Java StreamTokenizer) 
    Java Tutorial : Java IO (Java StreamTokenizer) 

    Java Tutorial : Java IO (Java StreamTokenizer) 
    StreamTokenizerDemo.java
    import java.io.IOException;
    import java.io.StreamTokenizer;
    import java.io.StringReader;
    
    public class StreamTokenizerDemo
    {
    
        public static void main(String[] args) throws IOException
        {
            StreamTokenizer streamTokenizer = null;
            StringReader stringReader = new StringReader("Peter had 1 pen.");
    
            streamTokenizer = new StreamTokenizer(stringReader);
    
            while (streamTokenizer.nextToken() != StreamTokenizer.TT_EOF)
            {
    
                if (streamTokenizer.ttype == StreamTokenizer.TT_WORD)
                {
                    System.out.println("Inside TT_Word = " + streamTokenizer.sval);
                }
                else if (streamTokenizer.ttype == StreamTokenizer.TT_NUMBER)
                {
                    System.out
                            .println("Inside TT_NUMBER = " + streamTokenizer.nval);
                }
            }
    
        }
    
    }
    
    Output
    Inside TT_Word = Peter
    Inside TT_Word = had
    Inside TT_NUMBER = 1.0
    Inside TT_Word = pen.
    
    Refer:
    https://docs.oracle.com/javase/8/docs/api/java/io/StreamTokenizer.html

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

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/afab0ff1466aae3a6d02c0935e804f2f099cf483/BasicJava/JavaIODemo_StreamTokenizerDemo_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
  • Monday, 17 October 2016

    Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7)



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

    Click the below Image to Enlarge 
    Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7) 
    Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7) 
    Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7) 
    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