Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    13
    Rep Power
    0

    Default [SOLVED] ReadLine(String fmt,Object... args) of Console class

    How does the method "public String readLine(String fmt, Object... args)" of the Console class work?
    any explanation with an example would be appreciated.
    Thanks In Advance!

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Hello Pooja,

    Using Console API( In Java 6) to output formatted content is much easy.

    You can call : console.format(String fmt, Object... args)
    OR
    console.printf(String fmt, Object... args) to print formatted data

    And The main method for handling user-input : readLine().

    This method ( readLine(String fmt, Object... args) ) is a combination of formatted output with user input. The method uses the java.util.Formatter syntax for the first argument, and applies the results of the args array.

    Example:
    Java Code:
    import java.io.*;
    
    public class ConsoleExample 
    {
    	public static void main(String[] args){
    		Console console = System.console();
    		if(console != null) {
    			 String formatString = "%1$4s %2$5s %3$10s%n";
    			 String name = console.readLine(formatString,"Please","Enter","Your Name :");
    		}
    	}
    }
    If any doubt please let me know.

    sanjeev,संजीव

  3. #3
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Hi Pooja,

    You can also see the Console API in action in my small tutorial at:
    Console applications with Java 6 | Little Tutorials

    Enjoy
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  4. #4
    Join Date
    Apr 2008
    Posts
    13
    Rep Power
    0

    Default

    Hi All,

    thank you for your prompt response!

    my doubt got cleared!:):)

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 1
    Last Post: 04-09-2008, 03:15 AM
  2. Java Swing class capturing output to the console
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 12:24 PM
  3. Reading a line from console using Scanner class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-18-2008, 12:52 PM
  4. Read from console (Scanner Class)
    By hey in forum New To Java
    Replies: 10
    Last Post: 12-11-2007, 11:11 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •