亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

以下代碼是關于連接池的,麻煩大佬幫忙看看~

以下代碼是關于連接池的,麻煩大佬幫忙看看~

LEATH 2022-01-06 09:05:02
InputStream is = getClass().getResourceAsStream("db.properties");Properties dbProps = new Properties();try {dbProps.load(is);}catch (Exception e) {System.err.println("不能讀取屬性文件. " +"請確保db.properties在CLASSPATH指定的路徑中");return;}String logFile = dbProps.getProperty("logfile", "DBHelp.log");System.out.println(logFile);try {log = new PrintWriter(new FileWriter(logFile, true), true);}catch (IOException e) {System.err.println("無法打開日志文件: " + logFile);log = new PrintWriter(System.err);}各位大蝦幫忙翻譯一下,越詳細越好
查看完整描述

1 回答

?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

InputStream is = getClass().getResourceAsStream("db.properties"); //文件流從當前文件夾中讀取db.properties文件
Properties dbProps = new Properties(); //創建屬性文件這個類
try {
dbProps.load(is); //把讀取的那個文件(db.properties)加裁到dbProps屬性類中
}
catch (Exception e) {
System.err.println("不能讀取屬性文件. " +
"請確保db.properties在CLASSPATH指定的路徑中");
return; //出現異常的就返回空值
}
String logFile = dbProps.getProperty("logfile", "DBHelp.log"); //在db.properties文件中通過鍵值logfile尋找對應的值
System.out.println(logFile); //打印這個字符串的值
try {
log = new PrintWriter(new FileWriter(logFile, true), true);
} //PrintWriter讀取文件,FileWriter寫入文件,把logFile字符串寫入FileWriter類中,再通過PrintWriter類讀取出來賦給log.
catch (IOException e) {
System.err.println("無法打開日志文件: " + logFile);
log = new PrintWriter(System.err); //捕捉異常,System.err,err是System類的靜態字段,"標準"錯誤輸出流的意思。
}

好好學,慢慢來,一開始是看著有點麻煩的。



查看完整回答
反對 回復 2022-01-10
  • 1 回答
  • 0 關注
  • 229 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號