15:IO之File、Properties类

第一  File类

一、概述:File类是有文件或文件件封装而来的对象,可以操作其属性信息,这个类的出现弥补了流的不足,流只能操作数据

1、特点:

1)用来将文件或文件夹封装成对象

2)方便于对文件与文件夹的属性信息进行操作

3)File对象可以作为多数传递给流的构造函数

2、File类常见方法:

实例:
  1. public class FileDemo {  
  2.     public static void main(String[] args) {  
  3. //      consMethod();  
  4. //      method();  
  5. //      listFilesDemo();  
  6. //      File dir = new File("E:\\develop\\eclipse space\\android workspace\\Test_java\\src");  
  7. //      showDir(dir);  
  8. //      method_1();  
  9. //      method_2(100);  
  10.     }  
  11.    /**  
  12.      * 构造方法演示  
  13.      */  
  14.     public static void consMethod(){  
  15.         //创建file对象,可以将已有的和未出现的文件或目录封装成对象  
  16.         File f1 = new File("C:" + File.separator + "a.txt");//File.separator跨平台的目录分隔符  
  17.         File f2 = new File("c:\\abc","b.txt");//C:\\abc\\b.txt一样,但是两个参数更灵活,可以目录不变,文件变  
  18.           
  19.         File d = new File("c:\\abc");  
  20.         File f3 = new File(d,"c.txt");  //这俩个和f2一样,不过f2目录是字符串对象,只能操作字符串方法
  21.           
  22.         System.out.println("f1: " + f1);  
  23.         System.out.println("f2: " + f2);  
  24.         System.out.println("f3: " + f3);  
  25.     }  
  26.      
  27.     /**  
  28.      * 演示File类的一些常用方法  
  29.      */  
  30.     public static void method_1(){  
  31.         File f = new File("file.txt");  
  32.       
  33.          //exists()方法查看文件或目录是否存在  
  34.         System.out.println("exists:" + f.exists());  
  35.         //测试应用程序是否可以执行此抽象路径名表示的文件。  
  36.         System.out.println("canExecute:" + f.canExecute());  
  37.       
  38.   //创建文件夹  
  39. //      File dir = new File("C:\\ab\\c\\v\\g");  
  40. //      System.out.println("mkdir:" + dir.mkdir());//最多只能创建两级目录,已经存在或失败返回false  
  41. //      System.out.println("mkdirs:" + dir.mkdirs());//创建多级目录  
  42.           
  43.         File f1 = new File("c:\\ab\\d.java");  
  44.         try {  
  45.             f1.createNewFile();//createNewFile创建新文件  
  46.         } catch (IOException e) {  
  47.             e.printStackTrace();  
  48.         }  
  49.        
  50.         //判断文件对象是否是文件或目录时,必须要先判断文件对象封装内容是否存在  
  51.         //通过exists方法  
  52.         System.out.println("isDir:" + f1.isDirectory());//是否是目录  
  53.         System.out.println("isFile:" + f1.isFile());//是否是文件  
  54.           
  55.         //获取路径  
  56.         System.out.println("path: " + f1.getPath());  
  57.         System.out.println("abspath: " + f1.getAbsolutePath());  
  58.         System.out.println("parent: " + f1.getParent());
  59. //该方法返回的是绝对路径中的父目录。如果获取的是相对路径,返回null。  
  60.         //如果相对路径中有上一层目录那么该目录就是返回结果。  
  61.           
  62.         //重命名,其实就是远文件再创建一个新文件,再把内容写入文件  (复制+重命名)
  63.         File f2 = new File("c:\\ab\\d.java");  
  64.         File f3 = new File("d:\\d.java");  
  65.         System.out.println("rename:" + f2.renameTo(f3));  
  66.     }  
  1. long len = file.length(); //文件的长度
  2. long time = file.lastModified(); //最后修改时间,可是时间是
  3.   Date date = new Date(time); //变成有效的格式时间
  4.  DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 
  5. String str_time = dateFormat.format(date); 
  6.   
  7. System.out.println("len:"+len); 
  8. System.out.println("time:"+time);
  9. System.out.println("str_time:"+str_time);

  10. public static void listRootsDemo() {
  11.   File file = new File("d:\\");
  12.   System.out.println("getFreeSpace:"+file.getFreeSpace()); 可用空间
  13.   System.out.println("getTotalSpace:"+file.getTotalSpace()); 容量
  14.   System.out.println("getUsableSpace:"+file.getUsableSpace()); 可用空间,是给虚拟机用的
File[] files  = File.listRoots();
 for(File file : files){ //输出的是自己电脑上的各个盘的盘名
System.out.println(file);

list方法(重点)
   * 获取当前目录下的文件以及文件夹的名称,包含隐藏文件。
   * 调用list方法的File对象中封装的必须是目录。
   * 否则会发生NullPointerException
   * 如果访问的系统级目录也会发生空指针异常。
   *
   * 如果目录存在但是没有内容,会返回一个数组,但是长度为0.
  1. public static void listDemo() {
  2. File file = new File("c:\\"); // a.txt错误
  3. String[] names = file.list();
  4. System.out.println(names.length);
  5. for (String name : names) {
  6. System.out.println(name);
  7. }
  8. }

如果是是获取.java文件,需要过滤器
  1. public class FilterBytxt implements FilenameFilter(文件名过滤) { //过滤器,过滤txt文件
  2. public boolean accept(File dir, String name) {
  3. // System.out.println(dir+"---"+name);
  4. return name.endsWith(".txt");
  5. }
  6. }
  7. //可是每次过滤txt,过滤Java又得改。这个方法可以这样写
  8. public class SuffixFilter implements FilenameFilter {
  9. private String suffix ;
  10. public SuffixFilter(String suffix) { 传个什么过滤什么
  11. super();
  12. this.suffix = suffix;
  13. }
  14. @Override
  15. public boolean accept(File dir, String name) {
  16. return name.endsWith(suffix);
  17. }
  18. }
  19. public static void listDemo_2() {
  20. File dir = new File("c:\\");
  21. String[] names = dir.list(new FilterBytxt );//(new SuffixFilter(".txt"));
  22. for(String name : names){
  23. System.out.println(name);
  24. }
  25. }
  listFiles()方法返回File对象  ,还有文件过滤和文件名过滤(常用),拿了对象拿名字和大小很简单
  list是过滤文件名,不能过滤文件
    1. public static void listFilesDemo(){
    2. File dir = new File("C:\\");
    3. File[] files = dir.listFiles();
    4. for(File f : files){
    5. System.out.println(f.getName() + "..." + f.length());
    6. }
    7. }
    8. }

  1. String[] names = file.list();
  2. System.out.println(names.length);
  3. for(String name : names){
  4. System.out.println(name);

  1. public class FilterByHidden implements FileFilter(文件过滤) { //过滤器,过滤隐藏文件,用 listFiles
  2. @Override
  3. public boolean accept(File pathname) {
  4. return !pathname.isHidden(); //不要隐藏为真
  5. }
  6. }
  7. public static void listDemo_3() {
  8. File dir = new File("c:\\");
  9. File[] files = dir.listFiles(new FilterByHidden());
  10. for(File file : files){
  11. System.out.println(file);
  12. }
  13. }

 需求:对指定目录进行所有内容的列出(包含子目录中的内容)
 也可以理解为 深度遍历。不要遍历C、d、e盘,太复杂,会发生空指针异常
用listfiles

public class FileTest {
 public static void main(String[] args) {
  File dir = new File("e:\\demodir");
  listAll(dir,0);
 }
 public static void listAll(File dir,int level) {//计数器level,增加一个目录就记录缩进一次,多个方法要记数,所以要传进去,不要定义
 每个目录都要传进这个参数里边去listAll(File dir,int level),来打印目录
  System.out.println(getSpace(level)+dir.getName()); //方法里调用方法,递归
 
 //获取指定目录下当前的所有文件夹或者文件对象
  level++; 
//只遍历用增强,操作角标用普通for
  File[] files = dir.listFiles();
  for(int x=0; x<files.length; x++){
   if(files[x].isDirectory()){
    listAll(files[x],level);
如果是目录,继续列,然后循环,再判断,再列,可是不知道有几级目录,可以
listAll(File dir,int level)这个方法是列目录中的内容,如果files[x]是个目录的话,可以将
files[x]传进 listAll就可以了,就可以列出这个目录的内容
   }
   else
    System.out.println(getSpace(level)+files[x].getName()名字,也可以是路径);这个打印的都是文件
  }
 }
 private static String getSpace(int level) {//缩进
 
  StringBuilder sb = new StringBuilder();
 
  sb.append("|--");
  for(int x=0; x<level; x++){
   sb.insert(0,"|  ");//从0参入
  }
  return sb.toString();
 }
  1.    public static void method(){  
  2.         File dir = new File("C:\\");  
  3.         String[] names = dir.list(new FilenameFilter() {  
  4.               
  5.             @Override  
  6.             public boolean accept(File dir, String name) {  
  7. //              System.out.println("dir:" + dir + ".....name::" + name);  
  8.                 return name.endsWith(".txt");  
  9.             }  
  10.         });  
  11.           
  12.         System.out.println("list.len:::" + names.length);  
  13.         for(String name : names){  
  14.             System.out.println(name);  
  15.         }  
  16.     } 

递归对于每次循环都是用同一个功能的函数,即函数自身调用自身,这种表现形式或手法,称为递归。

注意:

1、限定条件,是作为结束循环用的,否则是死循环

public static void show(){

  method();


 }

 public static void method(){

 show();

 }

2、注意递归的次数,尽量避免内存溢出。因为每次调用自身的时候都会先执行下一次调用自己的方法那个方法,所以会不断在栈内存中开辟新空间,次数过多,会导致内存溢出。


实例一:求和和求二进制

  1.      * 递归方法演示  
  2.     public static int method_2(int num){  
  3. //      //求和  
  4. //      if(num == 1){  
  5. //          return 1;  
  6. //      }  
  7. //      return num + method_2(num - 1);  
  8.           
  9.         //求二进制  
  10.         StringBuilder sb = new StringBuilder();  
  11.         if(num > 0){  
  12.             method_2(num/2);  
  13.             int i = num%2;  
  14.             sb.append(i);  
  15.         }  
  16.         System.out.println(sb.toString());  
  17.         return -1;  
  18.     }



实例二:显示所有目录下的文件,也就是说只要是目录就被循环

思路:既然要显示所有文件,就是要循环每一个文件夹,找出所有文件,这里操作文件夹的动作都是一样的,所有需要用到递归:

  1.      * 显示所有目录下的文件,也就是说只要是目录就被循环 
  2.     public static void showDir(File dir){  
  3.         System.out.println(dir);  
  4.         File[] files = dir.listFiles();  
  5.         for(File f : files){  
  6.             if(f.isDirectory()){  
  7.                 showDir(f);  
  8.             }else{  
  9.                 System.out.println(f);  
  10.             }  
  11.         }  
  12.     }

 实例三:删除一个带内容的目录。
 *
 * 原理:必须从最里面往外删。
 * 需要进行深度遍历。

  1. public class RemoveDirTest {
  2. public static void main(String[] args) {
  3. File dir = new File("e:\\demodir");
  4. // dir.delete();
  5. removeDir(dir);
  6. }
  7. public static void removeDir(File dir) {
  8. File[] files = dir.listFiles();
  9. for (File file : files) {
  10. if (file.isDirectory()) {
  11. removeDir(file);
  12. } else {
  13. System.out.println(file + ":" + file.delete());
  14. }
  15. }
  16. System.out.println(dir + ":" + dir.delete());
  17. }
  18. }

综合练习---文件清单列表
 * 获取指定目录下,指定扩展名的文件(包含子目录中的)
 * 这些文件的绝对路径写入到一个文本文件中。
 *
 * 简单说,就是建立一个指定扩展名的文件的列表。
 *
 * 思路:
 * 1,必须进行深度遍历。
 * 2,要在遍历的过程中进行过滤。将符合条件的内容都存储到容器中。多了存储起来,想怎么操作都行
 * 3,对容器中的内容进行遍历并将绝对路径写入到文件中。
  1. public class Test {
  2. public static void main(String[] args) throws IOException {
  3. File dir = new File("e:\\java0331");
  4. FilenameFilter filter = new FilenameFilter() {// 过滤器,匿名内部类
  5. public boolean accept(File dir, String name) {
  6. return name.endsWith(".java");
  7. }
  8. };
  9. List<File> list = new ArrayList<File>();
  10. getFiles(dir, filter, list);
  11. File destFile = new File(dir, "javalist.txt");// 目的文件,当前文件
  12. write2File(list, destFile);
  13. }
  14. /**
  15. * 对指定目录中的内容进行深度遍历,并按照指定过滤器,进行过滤, 将过滤后的内容存储到指定容器List中。 File
  16. * dir,FilenameFilter filter,List<File> list一个目录,文件名过滤,存储的容器
  17. */
  18. public static void getFiles(File dir, FilenameFilter filter, List<File> list) {
  19. File[] files = dir.listFiles();
  20. // 深度遍历
  21. for (File file : files) {
  22. if (file.isDirectory()) {
  23. // 递归
  24. getFiles(file, filter, list);
  25. } else {
  26. // 对遍历到的文件进行过滤器的过滤。将符合条件File对象,存储到List集合中。
  27. if (filter.accept(dir, file.getName())) {
  28. list.add(file);
  29. }
  30. }
  31. }
  32. }
  33. // 将集合写到文件去
  34. public static void write2File(List<File> list, File destFile)
  35. throws IOException {
  36. BufferedWriter bufw = null;
  37. try {
  38. bufw = new BufferedWriter(new FileWriter(destFile));
  39. for (File file : list) {
  40. bufw.write(file.getAbsolutePath());
  41. bufw.newLine();
  42. bufw.flush();
  43. }
  44. } /*
  45. * catch(IOException e){//可以写可以不写
  46. *
  47. * throw new RuntimeException("写入失败"); }
  48. */
  49. finally {
  50. if (bufw != null)
  51. try {
  52. bufw.close();
  53. } catch (IOException e) {
  54. throw new RuntimeException("关闭失败");
  55. }
  56. }
  57. }
  58. }


实例四:将一个指定目录下的java文件的绝对路径,存储到一个文本文件中。

思路:
  1、对指定目录进行递归
  2、获取递归过程中所有的java文件
  3、把路径存放在集合中
  4、把集合中的数据写入文件

  1. * 将一个指定目录下的java文件的绝对路径,存储到一个文本文件中。
  2. *
  3. * 思路:
  4. * 1、对指定目录进行递归
  5. * 2、获取递归过程中所有的java文件
  6. * 3、把路径存放在集合中
  7. * 4、把集合中的数据写入文件
  8. */
  9. public class JavaFileList {
  10. public static void main(String[] args) {
  11. // 指定查找路径
  12. File dir = new File(
  13. "E:\\develop\\eclipse space\\android workspace\\Test_java");
  14. // 定义集合用于存储取到的java路径
  15. List<File> list = new ArrayList<File>();
  16. fileToList(dir, list);// 调用查找文件方法
  17. // System.out.println(list.size());
  18. // 指定写入文件路径
  19. File file = new File("c:\\", "javalist.txt");
  20. writeToFile(list, file.toString());// 调用写入文件的方法
  21. }
  22. /*
  23. * 获取指定目录下的java文件
  24. */
  25. public static void fileToList(File dir, List<File> list) {
  26. File[] files = dir.listFiles();// 返回该目录下的文件对象
  27. for (File f : files) {
  28. if (f.isDirectory()) {
  29. fileToList(f, list);
  30. } else {
  31. if (f.getName().endsWith(".java"))
  32. ;// 找出java文件
  33. list.add(f);
  34. }
  35. }
  36. }
  37. /*
  38. * 将数据写入文件中
  39. */
  40. public static void writeToFile(List<File> list, String filepath) {
  41. BufferedWriter bfw = null;
  42. try {
  43. bfw = new BufferedWriter(new FileWriter(filepath));
  44. for (File f : list) {
  45. String path = f.getAbsolutePath();// 获取文件绝对路径
  46. bfw.write(path);
  47. bfw.newLine();
  48. bfw.flush();
  49. }
  50. } catch (IOException e) {
  51. e.printStackTrace();
  52. } finally {
  53. if (bfw != null) {
  54. try {
  55. bfw.close();
  56. } catch (IOException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. }
  61. }
  62. }


第二  Properties类

一、概述:

1、Properties是Hashtable的子类,也就是map集合的子类,所有具备Map集合的特点,而且它里面还有存储的键值对,都是字符串,无泛型定义。是集合中和IO技术相结合的集合容器。

2、特点:

1)可用于键值对形式的配置文件

2)在加载时,需要数据有固定的格式,常用的是:键=值

二、特有方法:

1、设置和获取元素:

Object setProperty(String key,String value)调用Hashtable 的方法put,将键和值存入到properties对象中

String getProperty(String key)用指定的键在此属性列表中搜索属性

Set<String> stringPropertyName()返回此属性列表中的键集

void load(InputStream ism)从输入流中读取属性列表(键和元素对)。

void load(Reader reader)按简单的面向行的格式从输入字符流中读取属性列表(键和元素对)。

实例:

  1. public class ProPertiesDemo {  
  2.     public static void main(String[] args) {  
  3.         getAndSet();  
  4. //      method();  
  5.         loadDemo();  
  6.     }  
  7.       
  8.     /*  
  9.      * 设置和获取元素。  
  10.      */  
    1.     public static void getAndSet(){  
  11.         Properties pro = new Properties();  
  12.           
  13.         pro.setProperty("zhangsan", "20");  
  14.         pro.setProperty("lisi", "30");  
  15.         System.out.println(pro);  //{zhangsan=20, lisi=12}
  16.         String value = pro.getProperty("lisi");  
  17.         System.out.println("getProperty: " + value);  //获取
  18.         pro.setProperty("lisi", "90");  //修改
  19.           
  20.         Set<String> names = pro.stringPropertyNames();  //取出所有键和值
  21.         for(String name : names){  
  22.               //String value = pro.getProperty(name );  
  23.             System.out.println(name + "::" + pro.getProperty(name));  
  24.              //System.out.println(name + "::" + value);  
  25.         }  
  26.          }  

list方法
  1. public static void methodDemo_2(){
  2. Properties prop = new Properties();
  3. //存储元素。
  4. prop.setProperty("zhangsan","30");
  5. prop.setProperty("lisi","31");
  6. ///prop = System.getProperties(); 打印出所有配置信息
  7. prop.list(System.out); //键和值全部打印出,但是不能操作,zhangsan=20,lisi=12
  8. }
  9. //store方法,将集合中数据存储到文件中
  10. public static void methodDemo_3() throws IOException {
  11. Properties prop = new Properties();
  12. //存储元素。
  13. prop.setProperty("zhangsan","30");
  14. prop.setProperty("lisi","31");
  15. //想要将这些集合中的字符串键值信息持久化存储到文件中。
  16. //需要关联输出流。
  17. FileOutputStream fos = new FileOutputStream("info.txt");
  18. //将集合中数据存储到文件中,使用store方法。
  19. prop.store(fos, "info");
  20. //"info"键值信息,不要写中文,Java中配置信息文件的后缀名是 properties,window是ini
  21.          fos.close(); 
     }

将集合中数据存储到文件中,使用store方法
文件中数据存储到集合中,使用load方法
  注意;必须要保证该文件中的数据是键值对
  需要使用到读取流

  1. public static void methodDemo_4() throws IOException {
  2. Properties prop = new Properties();
  3. FileInputStream fis = new FileInputStream("info.txt");
  4. //使用load方法。
  5. prop.load(fis);
  6. prop.list(System.out); //调试,验证
  7. }
   模拟load方法   
    1.     /*  
    2.      * 演示如何将流中的数据存储到集合中  
    3.      * 想要将info.txt中的数据存放在集合中进行操作  
    4.      *   
    5.      * 思路:  
    6.      * 1、用流关联info.txt文件  
    7.      * 2、读取一行数据,将改行数据用“=”切割  
    8.      * 3、将等号左边作为键,右边作为值存放到properties集合中  
    9.      */  
    10.     public static void method(){  
    11.         BufferedReader bfr = null;  
    12.         Properties pro = null;  
    13.         try {  
    14.             bfr = new BufferedReader(new FileReader("info.txt"));  
    15.             pro = new Properties();  
    16.               
    17.             String line = null;  
    18.             while((line=bfr.readLine()) != null){  
    19.              if(line.startsWith("#")) //#号开头的不切
    20.                continue;
    21.                 String[] arr = line.split("=");  
    22.                 pro.setProperty(arr[0], arr[1]);  //设置键值
    23.             }  
    24.         } catch (FileNotFoundException e) {  
    25.             e.printStackTrace();  
    26.         } catch (IOException e) {  
    27.             e.printStackTrace();  
    28.         }finally{  
    29.             if(bfr != null){  
    30.                 try {  
    31.                     bfr.close();  
    32.                     System.out.println(pro);  
    33.                 } catch (IOException e) {  
    34.                     e.printStackTrace();  
    35.                 }  
    36.             }  
    37.         }  
    38.     }  
    39.       
    40.    
    41.  //对已有的配置文件中的信息进行修改。
    42.  /*
    43.   * 读取这个文件。
    44.   * 并将这个文件中的键值数据存储到集合中。
    45.   * 在通过集合对数据进行修改。
    46.   * 在通过流将修改后的数据存储到文件中。
    47.  public static void test() throws IOException{
    48.   //要判断这个文件是否存在需要,把这个文件封装成对象进行操作
    49.   File file = new File("info.txt");
    50.   if(!file.exists()){
    51.    file.createNewFile();
    52.   }
    53.  //读取这个文件。
    54.   FileReader fr = new FileReader(file);
    55.   //创建集合存储配置信息。 
    56.   Properties prop = new Properties();
    57.   //将流中信息存储到集合中。
    58.   prop.load(fr);
    59.   prop.setProperty("wangwu", "16");
    60. //这里修改只是在内存中,而没有修改文件  
    61.    FileWriter fw = new FileWriter(file); //不能写到上边去,这个一创建就把原来的覆盖了
    62.   prop.store(fw," "); //不写注释了,当然也可以写
    63. // prop.list(System.out);
    64.   fw.close();
    65.   fr.close();
    66.  }

练习:限制程序运行次数。当运行次数到达5次时,给出,请您注册的提示。并不再让该程序执行。
个性化设置原理都是这样,设置修改完了关了再打开,还是修改后的,因为配置文件(ini后缀)改变了
  1.     /*  
  2.   思路:
  3.  * 1,应该有计数器。
  4.  * 每次程序启动都需要计数一次,并且是在原有的次数上进行计数。
  5.  * 2,计数器就是一个变量。 程序启动时候进行计数,计数器必须存在于内存并进行运算。
  6.  * 可是程序一结束,计数器消失了。那么再次启动该程序,计数器又重新被初始化了。
  7.  * 而我们需要多次启动同一个应用程序,使用的是同一个计数器。
  8.  * 这就需要计数器的生命周期变长,从内存存储到硬盘文件中。
  9.  *
  10.  * 3,如何使用这个计数器呢?
  11.  * 首先,程序启动时,应该先读取这个用于记录计数器信息的配置文件。
  12.  *  获取上一次计数器次数。 并进行试用次数的判断。
  13.  *  其次,对该次数进行自增,并自增后的次数重新存储到配置文件中。
  14.  *  
  15.  *
  16.  * 4,文件中的信息该如何进行存储并体现。
  17.  * 直接存储次数值可以,但是不明确该数据的含义。 所以起名字就变得很重要。
  18.  * 这就有了名字和值的对应,所以可以使用键值对。
  19.  * 可是映射关系map集合搞定,又需要读取硬盘上的数据,所以map+io = Properties.
  20.      *   
  21.      * 配置文件可以实现应用程序数据的共享。  
  1. public class PropertiesTest {
  2. public static void main(String[] args) throws IOException {
  3. getAppCount();
  4. }
  5. public static void getAppCount() throws IOException {
  6. // 将配置文件封装成File对象。
  7. File confile = new File("count.properties"); // 新建的配置
  8. if (!confile.exists()) {
  9. confile.createNewFile();
  10. }
  11. FileInputStream fis = new FileInputStream(confile); // confile是个文件
  12. Properties prop = new Properties();
  13. prop.load(fis); // 将文件的数据存储在集合中
  14. // 从集合中通过键获取次数(time是键)。
  15. String value = prop.getProperty("time");
  16. // 定义计数器。记录获取到的次数。不能直接time++,因为第一次运行时没有配置信息文件,新建了一个,但是没有数据,拿不到
  17. // 值,返回null
  18. int count = 0;
  19. if (value != null) {
  20. count = Integer.parseInt(value);// 次数是字符串,需要转换
  21. if (count >= 5) {
  22. // System.out.println("使用次数已到,请注册,给钱!");
  23. // return;
  24. throw new RuntimeException("使用次数已到,请注册,给钱!");
  25. }
  26. }
  27. count++;
  28. // 将改变后的次数重新存储到集合中。
  29. prop.setProperty("time", count + ""); // 名字:次数(转成字符串)
  30. FileOutputStream fos = new FileOutputStream(confile);
  31. prop.store(fos, "");
  32. fos.close();
  33. fis.close();
  34. }
  35. }








posted @ 2015-10-26 20:59  梦和远方  阅读(555)  评论(0编辑  收藏  举报