【发布时间】:2019-10-06 08:53:23
【问题描述】:
/* 一个使用属性列表的简单电话号码数据库 */
我在 Eclipse 中运行过这个程序很多次,但这显示了我未解决的编译问题
package phoneBook;
import java.io.*;
import java.io.File;
import java.util.Properties;
class meths
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
FileInputStream fin=null;
try {
fin=new FileInputStream("PhoneBook.txt");
}catch(FileNotFoundException e)
{
e.printStackTrace();
}
String name,number;
Properties pr=new Properties();
if(fin!=null)
{
try {
pr.load(fin); fin.close();
}catch(FileNotFoundException e)
{
e.printStackTrace();
}
}
void find() throws IOException
{
System.out.println("Enter name to find number");
name=br.readLine();
System.out.println("Number is:"+pr.getProperty(number));
}
void enter()
{
FileOutputStream fout=new FileOutputStream("PhoneBook.txt");
System.out.println("Enter name and number:");
name=br.readLine();number=br.readLine();
pr.put(name, number);
pr.store(fout, "Phone Boook");
}
void operation()
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int opt=0;
System.out.println("1 for stop operation\n2 for enter new entry\n3 for searching number");
while(opt!=1)
{
// Reading option
try {
opt=br.read();
} catch (IOException e) {
e.printStackTrace();
}// Read opearation is complete
switch(opt)
{
case 2: enter(); break;
case 3: find(); break;
}
}
}
}
public class PhoneBook
{
public static void main(String args[]) throws Exception
{``
meths ph=new meths();
ph.operation();
}
}
【问题讨论】:
-
你有大量没有任何方法的代码。在您修复它之前,您的代码将无法正常运行。 eclipse 无论如何都会尝试运行它的事实无济于事。
-
其实我是新来的学生。请你详细解释一下好吗?