IO流加集合加强练习题附答案(2)

2018-11-22 11:05

BufferedOutputStream(new FileOutputStream( \新建文件夹\\\\\ + file2.getName())); while ((lenght=bis.read(buf)) != -1) { bos.write(buf, 0, lenght); } bos.close(); bis.close(); } } } }

题目四:模拟用户登录功能实现。接收用户输入的用户名和密码,然后和文件中存储的用户名、密码匹配 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; //模拟用户登录功能实现。接收用户输入的用户名和密码,然后和文件中存储的用户名、密码匹配 public class Demo13 { static { File file = new File(\); try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { while (true) { System.out.println(\请选择功能 A:注册 B:登录\); String s = sc.next(); if (\.equalsIgnoreCase(s)) { // 注册 register(); } else if (\.equalsIgnoreCase(s)) { // 登录 login(); break; }else{ System.out.println(\您的输入不合法,请输入\\\或者\\\); } } } // 注册 private static void register() throws IOException { System.out.println(\请输入用户名:\); String Admin = sc.next(); System.out.println(\请输入密码:\); String password = sc.next(); String registerline = password + \ + Admin; BufferedWriter bw = new BufferedWriter(new FileWriter( \, true)); bw.write(registerline); bw.newLine(); System.out.println(\注册成功!您的账户名:\ + Admin + \您的密码:\ + password); bw.close(); } // 登录 private static void login() throws IOException, Exception { int count=0; while (true) { System.out.println(\请输入用户名:\); String Admin = sc.next(); System.out.println(\请输入密码:\); String password = sc.next(); String line = password + \ + Admin; BufferedReader br = new BufferedReader(new FileReader( \)); String str = null; boolean isLogin = false; while ((str = br.readLine()) != null) { if (line.equals(str)) { isLogin = true; break; } } br.close(); if (isLogin) { System.out.println(Admin + \欢迎您回来\); break; } else { count++; System.out.println(\密码输入错误!\); if (count == 5) {


IO流加集合加强练习题附答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:01计算机

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: