package edu.hyedu.visualjave.cap3;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.HashSet;import java.io.*;public class UsersSet { private HashSet<User> usersSet; public UsersSet() { usersSet=new HashSet<User>(); String str=null; String[] userStr=null; try { FileReader fir=new FileReader("/users.txt"); BufferedReader bir=new BufferedReader(fir); while((str=bir.readLine())!=null) { userStr =str.split(":"); usersSet.add(new User(userStr[0].trim(),userStr[1].trim(),Integer.parseInt(userStr[2]))); } } catch(FileNotFoundException e) { e.printStackTrace(); }catch(IOException e) { e.printStackTrace(); } } public boolean isValid(User user) { boolean userValid=false; if(usersSet.contains(user)) { userValid=true; } return userValid; }}错误信息:IWAV0048I Java Bean edu.hyedu.visualjave.cap3.UsersSet started with null constructorjava.io.FileNotFoundException: \users.txt (系统找不到指定的文件。) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) at java.io.FileInputStream.<init>(Unknown Source) at java.io.FileReader.<init>(Unknown Source) at edu.hyedu.visualjave.cap3.UsersSet.<init>(UsersSet.java:18) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:86)
|
|