The Artima Developer Community
Sponsored Link

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

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
Java Tutorial : Java IO (PrintStream-out-err) Posted: Aug 22, 2016 6:49 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: Java Tutorial : Java IO (PrintStream-out-err)
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement

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
  • Read: Java Tutorial : Java IO (PrintStream-out-err)

    Topic: Don’t ever read the comments Previous Topic   Next Topic Topic: Calculating the ROI on IT Innovation

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use