zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然java开发常用类库学习笔记:属性类Properties

    import java.util.Properties;
    public class PropertiesDemo01{
        public static void main(String args[]){
            Properties pro = new Properties() ;    // 创建Properties对象
            pro.setProperty("BJ","BeiJing") ;    // 设置属性
            pro.setProperty("TJ","TianJin") ;
            pro.setProperty("NJ","NanJing") ;    
            System.out.println("1、BJ属性存在:" + pro.getProperty("BJ")) ;
            System.out.println("2、SC属性不存在:" + pro.getProperty("SC")) ;
            System.out.println("3、SC属性不存在,同时设置显示的默认值:" + pro.getProperty("SC","没有发现")) ;
        }
    };
    import java.util.Properties;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    public class PropertiesDemo02{
        public static void main(String args[]){
            Properties pro = new Properties() ;    // 创建Properties对象
            pro.setProperty("BJ","BeiJing") ;    // 设置属性
            pro.setProperty("TJ","TianJin") ;
            pro.setProperty("NJ","NanJing") ;    
            File file = new File("D:" + File.separator + "area.properteis") ;    // 指定要操作的文件
            try{
                pro.store(new FileOutputStream(file),"Area Info") ;    // 保存属性到普通文件
            }catch(FileNotFoundException e){
                e.printStackTrace() ;
            }catch(IOException e){
                e.printStackTrace() ;
            }
        }
    };
    import java.util.Properties;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    public class PropertiesDemo03{
        public static void main(String args[]){
            Properties pro = new Properties() ;    // 创建Properties对象
            File file = new File("D:" + File.separator + "area.properteis") ;    // 指定要操作的文件
            try{
                pro.load(new FileInputStream(file)) ;    // 读取属性文件
            }catch(FileNotFoundException e){
                e.printStackTrace() ;
            }catch(IOException e){
                e.printStackTrace() ;
            }
            System.out.println("1、BJ属性存在:" + pro.getProperty("BJ")) ;
            System.out.println("2、SH属性存在:" + pro.getProperty("SH")) ;
        }
    };
    import java.util.Properties;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    public class PropertiesDemo04{
        public static void main(String args[]){
            Properties pro = new Properties() ;    // 创建Properties对象
            pro.setProperty("BJ","BeiJing") ;    // 设置属性
            pro.setProperty("TJ","TianJin") ;
            pro.setProperty("NJ","NanJing") ;    
            File file = new File("D:" + File.separator + "area.xml") ;    // 指定要操作的文件
            try{
                pro.storeToXML(new FileOutputStream(file),"Area Info") ;    // 保存属性到普通文件
            }catch(FileNotFoundException e){
                e.printStackTrace() ;
            }catch(IOException e){
                e.printStackTrace() ;
            }
        }
    };
    import java.util.Properties;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    public class PropertiesDemo05{
        public static void main(String args[]){
            Properties pro = new Properties() ;    // 创建Properties对象
            File file = new File("D:" + File.separator + "area.xml") ;    // 指定要操作的文件
            try{
                pro.loadFromXML(new FileInputStream(file)) ;    // 读取属性文件
            }catch(FileNotFoundException e){
                e.printStackTrace() ;
            }catch(IOException e){
                e.printStackTrace() ;
            }
            System.out.println("1、BJ属性存在:" + pro.getProperty("BJ")) ;
        }
    };
  • 相关阅读:
    JS匿名函数及调用及闭包
    js的变量提升和函数提升
    JS调用模式以及bind()方法
    转载:JS call()方法和apply()方法
    创建一个用于上传文件的表单
    POST 异步请求 url没有明文显示
    转载:nodejs res.end和res.send 区别
    HTTP中get和post区别
    通读cheerio API
    转载:JS数组reduce()和reduceRight()方法
  • 原文地址:https://www.cnblogs.com/tszr/p/12152781.html
Copyright © 2011-2022 走看看