Demo01:
public class PropertiesDemo01 { public static void main(String[] args) { Properties pt = new Properties(); pt.put("ggg",12); pt.put("xxx",13); pt.put("ccc",14); Set> entries = pt.entrySet(); for (Map.Entry
Demo02:Properties 的特有方法
Demo03:
package PropertiesDemo; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Properties; import java.util.Set; public class PropertiesDemo03 { public static void main(String[] args) throws IOException { // proStore(); proLoad(); } private static void proLoad() throws IOException { Properties pp = new Properties(); FileReader fr = new FileReader("/Users/verle/DeskTop/Properties.txt"); pp.load(fr); fr.close(); System.out.println(pp); Setstrings = pp.stringPropertyNames(); for (String tt:strings){ String value = pp.getProperty(tt); System.out.println(tt+","+value); } } private static void proStore() throws IOException { Properties pp = new Properties(); pp.setProperty("xx","22"); pp.setProperty("cc","23"); pp.setProperty("vv","24"); FileWriter fw = new FileWriter("/Users/verle/DeskTop/Properties.txt"); pp.store(fw,null); fw.close(); } }
Demo04:
package PropertiesDemo; import java.io.*; import java.util.Properties; import java.util.Set; public class PropertiesDemo04 { public static void main(String[] args) throws IOException { Properties pp = new Properties(); FileReader fr = new FileReader("/Users/verle/DeskTop/gg.txt"); pp.load(fr); fr.close(); String count = pp.getProperty("count"); int i = Integer.parseInt(count); if (i>=3){ System.out.println("游戏试玩已经结束,请充值!"); }else { GussNumber.start(); i++; Properties p2 = new Properties(); FileWriter f2 = new FileWriter("/Users/verle/DeskTop/gg.txt"); p2.setProperty("count",String.valueOf(i)); p2.store(f2,null); f2.close(); } } }
package PropertiesDemo; import java.util.Random; import java.util.Scanner; public class GussNumber { public static void start() { Random random = new Random(); int i = random.nextInt(100) + 1; while (true) { Scanner scanner = new Scanner(System.in); System.out.println("请输入你猜的数字:"); int number = scanner.nextInt(); if (number > i) { System.out.println("你猜的数字" + number + "大了"); } else if (number < i) { System.out.println("你猜的数字" + number + "小了"); } else { System.out.println("恭喜你猜对了!!"); break; } } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)