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) {
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库IO流加集合加强练习题附答案(2)在线全文阅读。
相关推荐: