Java Bo&Yang
java的交流从这里开始
posts - 8,comments - 6,trackbacks - 0
读取properties文件

           try {           

           File file = new File(System.getProperty("user.dir")
                                 + "/EMweb/WEB-INF/admininfo.properties");
            InputStream is = new FileInputStream(file);

            props.load(is);

            this.userName = props.getProperty("userName");
            this.userPassWord = props.getProperty("userPassWord");
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

      更改properties文件

        Properties prop = new Properties();
        File file = new File(System.getProperty("user.dir")
                                 + "/EMweb/WEB-INF/admininfo.properties");
        prop.setProperty("userName", String.valueOf(cUserName));
        prop.setProperty("userPassWord", String.valueOf(cUserPassWord));
        try {
            OutputStream fos = new FileOutputStream(file);
            prop.store(fos, "admininfo.properties");
            fos.close();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

这里面的关键是System.getProperty("user.dir") 返回当前工作目录

posted on 2006-05-12 15:50 Java BY 阅读(336) 评论(0)  编辑  收藏 所属分类: Bo java学习笔记

只有注册用户登录后才能发表评论。


网站导航: