publicclassInputUserInformation{/*从键盘输入,返回一个字符串*/publicStringinputName(){intcount;byte[]b=newbyte[256];Stringstr="";DataInputStreamdin=newDataInputStream(Sys...
public class InputUserInformation { /*从键盘输入,返回一个字符串*/ public String inputName () { int count; byte[] b = new byte[256]; String str = ""; DataInputStream din = new DataInputStream(System.in); BufferedInputStream in = new BufferedInputStream(din); try { count = in.read(b); str = new String(b,0,count); } catch (IOException e) { e.printStackTrace(); System.out.print("发送I/O错误!"); } finally { try { din.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } return str; } public String inputPassword () { int count; byte[] b = new byte[256]; String str = ""; DataInputStream din = new DataInputStream(System.in); BufferedInputStream in = new BufferedInputStream(din); try { count = in.read(b); str = new String(b,0,count); } catch (IOException e) { e.printStackTrace(); System.out.print("发送I/O错误!"); } finally { try { din.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } return str; } }
展开