Java: Out with the Old, In with the New

后端 未结 30 1965
遥遥无期
遥遥无期 2020-12-22 16:11

Java is nearing version 7. It occurs to me that there must be plenty of textbooks and training manuals kicking around that teach methods based on older versions of Java, whe

30条回答
  •  一整个雨季
    2020-12-22 16:42

    reading a string from standard input:

    Java pre-5:

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str = reader.readLine();
        reader.close();
    }
    catch (IOException e) {
        System.err.println("error when closing input stream.");
    }
    

    Java 5:

    Scanner reader = new Scanner(System.in);
    String str = reader.nextLine();
    reader.close();
    

    Java 6:

    Console reader = System.console();
    String str = reader.readLine();
    

提交回复
热议问题