Properties 基本知识 加try catch
来源:互联网 发布:淘宝销售属性 编辑:程序博客网 时间:2024/04/30 03:16
Properties 基本知识
如果不熟悉 java.util.Properties 类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的,如清单 1 所示。
import java.util.*;
- import java.io.*;
- public class LoadSample {
- public static void main(String args[]) throws Exception {
- Properties prop = new Properties();
- FileInputStream fis =
- new FileInputStream("sample.properties");
- prop.load(fis);
- prop.list(System.out);
- System.out.println("/nThe foo property: " +
- prop.getProperty("foo"));
- }
- }
上面的代码出现异常,在读写文件的时间在加入try ...catch 处理
Properties prop = new Properties();
try{
FileInputStream fis = new FileInputStream("c://sample.properties");
prop.load(fis);
prop.list(System.out);
String strIP = prop.getProperty("ip");
System.out.println(strIP);
}
catch(Exception ex)
{
ex.printStackTrace();//打印异常信息
}
finally
{
if (null != prop)
prop.clear();
}
}
- Properties 基本知识 加try catch
- sql server 2005中新增加的try catch学习
- sql server 2005中新增加的try catch学习
- try catch
- try{} catch{}
- try catch
- try...catch
- try{} catch(...){}
- try catch
- try-catch
- try catch
- try-catch
- try catch
- try catch
- try catch
- try catch
- try catch
- try {...} catch (){....}
- IIS5正常运行ASP
- FIND_IN_SET函数中MySql中的经典使用方法
- eclipse 快捷键
- MySQL的经典用法(二)----按月统计数据
- 无人驾驶
- Properties 基本知识 加try catch
- Eclipse提示
- MySQL的经典用法(五)----触发器
- 一种奇怪的使用debug方式,写到最后觉得后果很可怕[bsnhk原创]
- Eclipse常用
- Eclipse常用
- Eclipse常用
- iptable 初始动作 开发 ssh
- Hibernate工作原理