learning java 转换流
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class KeyinTest { public static void main(String[] args) throws IOException { var reader = new InputStreamReader(System.in); var br = new BufferedReader(reader); { String line = null; while ((line = br.readLine()) != null){ if (line.equals("exit")){ System.exit(0); } System.out.println("readline content:" + line); } } } }
output:
adddd
readline content:adddd
dasdf
readline content:dasdf
exit