- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
/* 使用属性列表的简单电话号码数据库 */
I had run this program many times in eclipse but this is showing me unresolved compilation proble
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();
}
}
最佳答案
这里是一个可能的更正:
package phoneBook;
import java.io.*;
import java.util.Properties;
class meths {
BufferedReader br;
FileInputStream fin;
String name, number;
Properties pr;
File file;
String path = "D:/PhoneBook.txt";
public meths() {
file = new File(path);
pr = new Properties();
br = new BufferedReader(new InputStreamReader(System.in));
//If file doesn't exist, create it and load it
if (!(file.exists() && file.canRead())){
try {
file.createNewFile();
} catch (IOException e) {
System.out.println("File can't be created");
}
}
try {
fin = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.out.println("File can't be read");
}
// If file is not empty, load properties
if (fin != null) {
try {
pr.load(fin);
fin.close();
} catch (IOException e) {
System.out.println("Properties not loaded");
}
}
}
void find() throws IOException {
System.out.println("\n>Enter name to find number:");
name = br.readLine();
System.out.println("Number is: " + pr.getProperty(name));
}
void enter() throws IOException {
System.out.println("\n>Enter the name :");
name = br.readLine();
System.out.println("\n>Enter the number :");
number = br.readLine();
FileOutputStream fout = new FileOutputStream(file);
pr.put(name, number);
pr.store(fout, "Phone Boook");
}
void choice() throws IOException {
System.out.println("\n>Enter your choice :");
}
public boolean isInteger(String chaine) {
try {
Integer.parseInt(chaine);
} catch (NumberFormatException e) {
return false;
}
return true;
}
void operation() throws IOException {
int opt = 0;
System.out.println("1 for stop operation\n2 for enter new entry\n3 for searching number\n");
while (opt != 1) {
choice();
String value = br.readLine();
if (isInteger(value)) {
opt = Integer.parseInt(value);
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();
}
}
控制台 View :
文件:
总之,我会说你必须学习基础知识才能理解类、构造函数、方法和成员的工作原理。
关于java.lang.错误: Unresolved compilation problem:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58255692/
我很绝望,现在已经两天(!!)天都没有解决方案来解决以下问题。 更新 Lion 后,我想使用最新版本的 rvm 安装额外的 rubies。 这是我之后调用 bundler 时发生的情况: /Users
我的问题: ajax 调用的无限循环会产生问题吗? 假设有这样的代码: ajaxcall(); function ajaxcall(){ jQuery.ajax({ typ
这是一个有趣的小项目,我已经开始尝试并最大限度地提高赢得办公室曲棍球池的机会。我试图找到最好的方法来选择 20 名能够在最高工资帽内给我最多分数的球员。 例如,假设原始数据由 玩家姓名 位置(前锋,后
我有一个总数为540000的数字列表。我想将此列表分为3个列表,每个列表总共180000。最有效的编程方法是这样做,假设数字列表是一个平面文件,每个数字为线? 最佳答案 听起来像Knapsack pr
抱歉,也许因为我不是英语,我不知道,但我找不到解决几个问题的任何资源;也许我用的词不正确.. 我想了解有关 iPhone 4 和 5 不同分辨率的更多信息。 首先:如果我开发针对 iPhone 4 分
在全局配置缓存后,如 docs ,如果我在 app.module 之外使用 CacheInterceptor,它会抛出错误。 app.module.ts const cacheConfig = {
我无法让 g:each 工作。我正在尝试遍历任何内容,但它永远不起作用 = 不生成任何 html。 索引.gsp Item ${i.name} 用户 Controller .g
在我的 XAML 文件中,我有一个这样声明的 ListBox:
想知道你是否可以帮助我: 我有一个名为initializeAll的方法: public final void initializeAll() { //other stuff........ rand
我尝试过使用 XML 和 JAVA 在我的 Android Activity 中创建一个 ImageView。这两次,我都能够获取我一天前创建的所有其他 PNG 资源以显示在 ImageView 中。
我需要你的帮助。这是什么意思? Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'
这是一段代码 function test() { this.value = "foo"; } $(document).ready(function () { test();
这是一些非常基础的东西。渲染期间引发异常:java.util.Locale.toLanguageTag()Ljava/lang/String; XML: 问题似乎出在 Edit
除其他来源外,我还使用 Stackoverflow 上的各种帖子,尝试实现我自己的 PHP 分类器,以将推文分类为正面、中性和负面类别。在编码之前,我需要弄清楚流程。我的思路和例子如下:
在过去的几周里,每当我在 Eclipse 上使用 SVN 插件时,我都会收到以下错误: Certificate Problem There is a problem with the site's s
我被拒绝运行以下功能(位于 /var/www/mysite/public_html/app/Controllers/Script.php) $structure = '/var/www/mysite/
我正在使用 ctags 为我的 Emacs 创建标签以使用 cygwin 从中读取符号。 Emacs 说 “访问标签表缓冲区:文件/home/superman/tags 不是有效的标签表” 这是我查找
我知道作为一种函数式语言,XSL 没有像传统的 for 循环(而是 for-each)那样的东西。 我正在尝试从可变数量的元素开始创建一个具有固定数量 (7) 的表。总之,我有
我正在使用RavenDB进行一些测试,以基于iphone应用程序存储数据。该应用程序将发送一个带有GPS key 的5个GPS坐标的字符串。我在RavenDB中看到每个文档约为664-668字节。这是
我无法理解我的应用程序的行为。我想创建一个简单的窗口 (1000x700px),分为两部分(分别为 250px 和 750px 宽度)。我尝试了以下代码: import java.awt.Color;
我是一名优秀的程序员,十分优秀!