📄 console.java
字号:
//******************************************************************
// Released under the DevelopMentor OpenSource Software License.
// Please consult the LICENSE file in the project root directory,
// or at http://www.develop.com for details before using this
// software.
//******************************************************************
package org.jawin.donated.win32.io;
import java.io.*;
/**
* Simple wrapper class for console input/output
*/
public class Console
{
/**
* Wraps System.in for reading in a line at time
*/
static BufferedReader input = new BufferedReader(new InputStreamReader((System.in)));
/**
* Prevents construction
*/
private Console()
{
}
/**
* Prints <code>prompt</code> and returns user's response
*/
public static String prompt(String prompt)
{
System.out.println(prompt);
try
{
return input.readLine();
}
catch (IOException ioe)
{
return null;
}
}
/**
* Prints <code>prompt</code> and forces user to enter
* <code>choice</code> before continuing
*/
public static void acceptChoice(String prompt, String choice)
{
System.out.println(prompt);
while (true)
{
try
{
if(choice.equals(input.readLine()))
break;
}
catch (IOException ioe)
{
}
}
}
/**
* Prints <code>prompt</code> and forces user to enter
* one of <code>choices</code> before continuing
*/
public static String acceptChoice(String prompt, String[] choices)
{
System.out.println(prompt);
while (true)
{
try
{
String response = input.readLine();
for (int n=0; n<choices.length; n++)
{
if (choices[n].equals(response))
{
return response;
}
}
}
catch (IOException ioe)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -