Java关于io和多线程的编程题,求代码
1个回答
展开全部
package know;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class T20 {
public static void main(String[] args) throws IOException {
Scanner s=new Scanner(System.in);
String username=null;
String password=null;
System.out.println("输入用户名:");
while(true){
if(username==null){
username=s.next();
System.out.println("输入密码:");
}else{
password=s.next();
}
if(password!=null){
s.close();
break;
}
}
BufferedReader br=null;
Map<String, String> map=new HashMap<String, String>();
try{
br=new BufferedReader(new InputStreamReader(new FileInputStream("d:/test.txt")));
String temp=null;
while((temp=br.readLine())!=null){
String[] ss=temp.split("=");
map.put(ss[0], ss[1]);
}
}catch(IOException e){
throw e;
}finally{
if(br!=null)
br.close();
}
String u=map.get("userName");
String p=map.get("password");
if(u.equals(username)&&p.equals(password)){
System.out.println("登录成功");
}else{
System.out.println("用户名或密码错误");
}
}
}
package know;
public class T21 {
public static void main(String[] args) throws InterruptedException {
String[] persons=new String[]{"甲","乙","丙","丁","午","己","庚","辛","壬","癸"};
for(int i=0;i<persons.length;i++){
System.out.println(persons[i]+"正在过山洞");
Thread.sleep(5000);
}
}
}
最后一个百度搜一个就行了,肯定比我画的好
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询