⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preferencesloader.java

📁 自动生成JAVA-Struts网站的程序
💻 JAVA
字号:
package com.sutternow.swingkar.Preferences;

import java.io.*;
import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: payne
 * Date: May 5, 2003
 * Time: 12:41:36 PM
 * To change this template use Options | File Templates.
 */
public class PreferencesLoader {
    private static final String propFilename = "prefernces.props";

    public static void storePerfernces(Preferences prefs) {
        String userDir = System.getProperty("user.home");
        File appDir = new java.io.File(userDir + File.separator +  ".swingkar" + File.separator);

        if (!appDir.exists()) {
            appDir.mkdir();
        }

        Properties props = new Properties();

        props.setProperty("author", prefs.getAuthorName());
        props.setProperty("company", prefs.getCompanyName());
        props.setProperty("packagename", prefs.getPackageName());
        props.setProperty("dateformat", prefs.getDateFormat());


        try {

            FileOutputStream settingsOut = new FileOutputStream(appDir.getAbsolutePath() +
                    File.separator + propFilename);
            props.store(settingsOut, "SwingKar Prefernces");
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }

    }

    public static Preferences loadPreferences() {
        Preferences prefs = new Preferences();
        Properties props = new Properties();
        String userDir = System.getProperty("user.home");
        File appDir = new java.io.File(userDir + File.separator + ".swingkar");
        File propFile =new File(appDir.getAbsolutePath() + File.separator + propFilename);

        if (!appDir.exists()) {
            appDir.mkdir();
        }
        if (!propFile.exists())  {
                     prefs.setAuthorName("author Name");
                     prefs.setCompanyName("Javanic");
                     prefs.setPackageName("com.sutternow");
                     prefs.setDateFormat("MM/dd/yyyy");

        }  else {
            try {
                props.load(new FileInputStream(propFile));

                prefs.setAuthorName(props.getProperty("author"));
                prefs.setCompanyName(props.getProperty("company"));
                prefs.setPackageName(props.getProperty("packagename"));
                prefs.setDateFormat(props.getProperty("dateformat"));

            } catch (Exception e) {
                e.printStackTrace();  //To change body of catch statement use Options | File Templates.
            }
        }

        return prefs;

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -