Monday 22 August 2016

Java Tutorial : Java IO (PrintStream-out-err)


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

Click the below Image to Enlarge
Java Tutorial : Java IO (PrintStream-out-err) 
PrintStreamDemo1.java
import java.io.IOException;
import java.io.PrintStream;

public class PrintStreamDemo1
{

    public static void main(String[] args) throws IOException

    {
        PrintStream printStream = null;
        try
        {
            /*
             * System.out
             * ----------
             * The "standard" output stream. This stream is
             * already open and ready to accept output data.
             * Typically this stream corresponds to display
             * output or another output destination
             * specified by the host environment or user.
             */
            printStream = new PrintStream(System.out);
            printStream.println(2500);
            printStream.println("Hello Peter");
            printStream.println(25.988);
            printStream.println(true);
        }
        finally
        {
            if (printStream != null)
            {
                printStream.close();
            }
        }

    }
}
Output
2500
Hello Peter
25.988
true
PrintStreamDemo2.java
import java.io.IOException;
import java.io.PrintStream;

public class PrintStreamDemo2
{

    public static void main(String[] args) throws IOException

    {
        PrintStream printStream = null;
        try
        {
            /*
             * System.err
             * ---------
             * The "standard" error output stream. This
             * stream is already open and ready to accept
             * output data. Typically this stream
             * corresponds to display output or another
             * output destination specified by the host
             * environment or user. By convention, this
             * output stream is used to display error
             * messages or other information that should
             * come to the immediate attention of a user
             * even if the principal output stream, the
             * value of the variable out, has been
             * redirected to a file or other destination
             * that is typically not continuously monitored.
             */
            printStream = new PrintStream(System.err);
            printStream.println("Error occured.");          
        }
        finally
        {
            if (printStream != null)
            {
                printStream.close();
            }
        }

    }
}
Output
Error occured.
PrintStreamDemo3.java
import java.io.IOException;

public class PrintStreamDemo3
{

    public static void main(String[] args) throws IOException

    {
        System.out.printf("%f", 25.89);
        System.err.println("\nSome error occured");
    }
}
Output
25.890000
Some error occured
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_PrintStream_out_err_app.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/6677706d119a4693a72878c56e3b8b5e20670e29/BasicJava/JavaIODemo_PrintStream_out_err_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