Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Java IO

  1. #1
    New Coder
    Join Date
    Sep 2002
    Location
    Johannesburg,South Africa
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Java IO

    I would like to read data from the console in Java. I know that I need to use BufferedInputstream and/or DataInputStream but I need an example. Something like:-

    Int valoe;
    System.out.println("Please enter the percentage!");
    then the the user enters/types: 60%

    and then valoe = 60%.

    I hope this makes sense!

    Your help will be highly appreciated.

    Thank you,

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Code:
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String pct = null;
    
    try{ 
        pct = br.readLine(); 
    }
    catch(IOException e){ 
        System.out.println("IO error has occurred"); 
        System.exit(1); 
    }
    
    System.out.println("You entered, " + pct);
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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