Console/Terminal for J2SE 1.4?

Hey does anyone know how to get user input from a keyboard in Java J2SE 1.4?

In later versions I can use Scanner, but that’s not an option in this version.

Managed to get something working!

Credits to @Engle
Post in the lounge:
https://forum.level1techs.com/t/the-lounge-one-more-for-the-road-edition/166891/390?u=derbshey

Here’s the code I’m using right now:

import java.io.BufferedReader; 
import java.io.InputStreamReader; 

public class Main2 
{
    public static void main (String [] args)
    {
        BufferedReader bR = new BufferedReader(new InputStreamReader(System.in)); 
        
        int pL = 0; 
        String Test = ""; 
        
        System.out.println("Enter the password length. "); 
        
        try 
        {
            Test = bR.readLine(); 
        }
        catch (Exception e) 
        {
            
        }
        
        pL = Integer.parseInt(Test); 
        
        System.out.println("The password length you entered is: " + pL); 
    }
}

Kind of a tricky one because you have to use two imports instead of one.
Regardless, it works.

1 Like

That was the oldschool way to do it. I still use that method today. Last time I used scanner about 6 years ago, it would frek out with some utf-8 inputs. I asume that is fixed but I would rather deal with raw streams.

1 Like