운행 횟수 제한

2567 단어 JavaIO
package yuwei.com;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class CountDemo {

    public static void countRecord() throws IOException {
        //    
        File file = new File("count.ini");
        //    
        if(!file.exists()) {
            file.createNewFile();
        }
        //    
        Properties prop = new Properties();
        FileInputStream fis = new FileInputStream(file);

        prop.load(fis);
        int count = 0;
        String values = prop.getProperty("time");
        if(values!=null) {
            count = Integer.parseInt(values);
            if(count >= 5) {
                System.out.println("fail");
            }
        }
        count++;
        prop.setProperty("time", count+"");
        FileOutputStream fos = new FileOutputStream(file);
        prop.store(fos, "");
        fis.close();
        fos.close();
    }
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        countRecord();
    }

}

좋은 웹페이지 즐겨찾기