Monday 22 August 2016

Java Tutorial : Java IO (PrintStream-printf)


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

PrintStreamDemo.java
import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;

public class PrintStreamDemo
{

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

    {
        PrintStream printStream = null;
        try
        {
            printStream = new PrintStream(System.out);
            int intValue = 98;
            double doubleValue = 899.87;
            /*
             * public PrintStream printf(String format,
             *                              Object... args)
             * 
             * A convenience method to write a formatted
             * string to this output stream using the
             * specified format string and arguments.
             */
            printStream.printf("i = %d and k = %f", intValue, doubleValue);
            Date date = new Date();
            System.out.println();
            /*
             * Prints an object.
             */
            printStream.print(date);

        }
        finally
        {
            if (printStream != null)
            {
                printStream.close();
            }
        }

    }
}
Output
i = 98 and k = 899.870000
Mon Aug 15 09:08:04 IST 2016
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_PrintStream_printf_App.zip?attredirects=0&d=1

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

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