package FileT.Day7;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class PropertiesTest {
public static void main(String[] args) {
Properties p =new Properties();
p.put("001","棋棋");
p.put("002","QQ");
p.put("003","KK");
p.put("004","瑶瑶");
Set<Map.Entry<Object, Object>> entries = p.entrySet();
for (Map.Entry<Object, Object> a :entries) {
System.out.println(a.getKey()+" "+a.getValue());
}
p.setProperty("005","婠婠");
p.setProperty("006","七七");
p.setProperty("007","鬼鬼");
p.setProperty("008","世使");
System.out.println(p.getProperty("004"));
Set<String> strings = p.stringPropertyNames();
for (String a :strings) {
System.out.println(a+" "+p.getProperty(a));
}
}
}
package FileT.Day7;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
public class PropertiesDemo {
public static void main(String[] args) throws IOException {
write();
read();
}
private static void read() throws IOException {
Properties p =new Properties();
p.load(new FileReader("fox.txt"));
Set<String> strings = p.stringPropertyNames();
for (String a :strings) {
System.out.println(a+" "+p.getProperty(a));
}
}
private static void write() throws IOException {
Properties p =new Properties();
p.put("001","棋棋");
p.put("002","QQ");
p.put("003","KK");
p.put("004","瑶瑶");
p.store(new FileWriter("fox.txt"),null);
}
}
package FileT.Day7;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Random;
import java.util.Scanner;
public class GameDemo {
public static void main(String[] args) throws IOException {
Properties p =new Properties();
FileReader fr =new FileReader("fox.txt");
p.load(fr);
fr.close();
int i =Integer.parseInt(p.getProperty("count"));
FileWriter fw =new FileWriter("fox.txt",true);
if (i>=3){
System.out.println("游戏试玩已结束,想再次尝试请充值!");
fw.close();
}else {
System.out.println("你还剩"+(3-i-1)+"次试玩机会!");
i++;
p.setProperty("count",String.valueOf(i));
p.store(fw,null);
game.start();
}
}
}
class game{
public static void start(){
System.out.println("猜数字游戏启动");
Random random =new Random();
int i = random.nextInt(100);
Scanner sc =new Scanner(System.in);
System.out.print("请输入数字:");
int i1 = sc.nextInt();
while(true){
if (i1<i){
System.out.println("猜小啦!重新猜吧!");
i1 =sc.nextInt();
}else if (i1>i){
System.out.println("猜大啦!重新猜吧!");
i1 =sc.nextInt();
}else {
System.out.println("恭喜你猜中啦!");
return;
}
}
}
}
class de{
public static void main(String[] args) throws IOException {
Properties p =new Properties();
p.put("ccc","1");
FileWriter fw =new FileWriter("fox.txt");
p.store(fw,null);
fw.close();
}
}