Thread: java input help

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    5

    java input help

    I'll get straight to the point.


    I have the following procedure:

    Code:
     
    
    public static String readLine (String prompt) {
       	System.out.print( prompt );
       	try {
       	InputStreamReader isr = new InputStreamReader (System.in);
       	BufferedReader br = new BufferedReader(isr);
       	String s = br.readLine ();
       	System.out.println ("");
       	return s;
       	}
       	catch (IOException e)
       	{ System.out.println("IO Exception ");
    	   e.printStackTrace();
       	System.exit (-1);
       	}
    	return "EXCEPTION";
    } // end readLine
    and this procedure:

    Code:
    public static void login() 
    {
    	String user = readLine("user:") ;
    	String pass = readLine("pass:") ;
    System.out.println("user is " + user + " pass is " + pass) ;
    
    
    
    } // end login

    both procedures are in the same .java file.
    My question is, when im running this in a dos prompt window, If i want input from a file, I type
    java [classname] < [input file]
    right?

    but when I have a simple text file with the following data:

    scott
    tiger

    .. and I direct this file into my program with the above line of code, I get the following output:

    "user is scott pass is null "

    can someone please tell me why the second line in the text file is not being read in?

    thanks in advance.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    No offense or anything, but what is the title of this site?

    You might want to try www.javaranch.com where there are a lot more java developers.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Even though this isn't "javaprogramming.com", I'll suggest that you try putting a blank newline or some dummy text after the password.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM