Java基礎 筆記(七)

2021-07-04 18:02:08 字數 1386 閱讀 2884

properties:

hashtable的子類,屬於集合類。儲存屬性累心公的鍵值對, 鍵和值預設都是string 是集合中可以和流結合使用的乙個集合類

properties pro = new properties();

pro.setproperty(「name」, 「tom」);

pro.setproperty(「age」, 「19」);

pro.setproperty(「***」, 「boy」);

system.out.println(pro);

// 獲得所有屬性名的集合

setnames = pro.stringpropertynames();

iteratorit = names.iterator();

while (it.hasnext())

與檔案流結合使用:

通過properties類載入.properties檔案,並讀取資訊

1 流 2 建立properties物件,載入屬性檔案 3 通過properties物件的方法,將資訊讀取出來

// 寫入properties檔案

static void writeproperties(file file, map

資料流:專門用來寫基本型別資料,讀和寫的順序嚴格對應

datainputstream(inputstream )

readint()

readdouble()

readutf()

dataoutputstream(outputstream)

writeint()

writedouble()

writeutf()

flush()

// 建立乙個資料流

dataoutputstream os = new dataoutputstream(new fileoutputstream(

「src/data.txt」));

os.writedouble(12.2);

os.writeint(10);

os.writeutf(「好好學習」);

os.flush();

// 讀

datainputstream is = new datainputstream(new fileinputstream(

"src/data.txt"));

system.out.println(is.readdouble());

system.out.println(is.readint());

system.out.println(is.readutf());

Python基礎筆記 七

語法 for 變數 in 迭代序列 即列表,元組,字典,集合或字串 迴圈體 for 迴圈訪問列表 list woodman alan bobo for name in list print name 輸出結果 woodman alan bobo 語法 for 變數 in 迴圈序列 迴圈體 else ...

java基礎七 流程控制

什麼是流程控制語句?含義 可以 控制程式的執行流程的語句。分類 順序結構 選擇結構 迴圈結構 流程控制語句是從上往下,依次執行。選擇結構 if語句 switch語句 if語句 寫法1 if 比較表示式 先計算比較表示式的值,如果是true,就執行語句體 如果是false,就不執行語句體 注意 比較表...

java學習基礎第七講

for 表示式 判斷條件 表示式 執行順序 看表示式 值賦給變數 變數去判斷條件,如果條件成立執行迴圈體 如果不成立不執行.for迴圈變數的作用域問題 在for迴圈表示式內定義的變數只能在當前迴圈體使用,如果變數在for迴圈體外面 則作用域在for迴圈外使用,for迴圈內不可重複定義 while 判...