Java操作ini文件 ,解决properties文件中无法读取换行及空格

1、依赖jar包

ini4j-0.5.4.jar

2、官网

http://ini4j.sourceforge.net/

3、测试例子

[java] view plain copy

    package cn.yjx.ini4j;  
      
    import java.io.File;  
    import java.io.IOException;  
      
    import org.ini4j.Wini;  
      
    public class Ini4jTest {  
        public static void main(String[] args) throws IOException {  
            test1();     
        }  
      
        public static void test1() throws IOException {  
            String fileName = "D:\\dev\\Java\\MyEclipse_workspace\\Test\\src\\cn\\yjx\\ini\\test1.ini";  
            Wini ini = new Wini(new File(fileName));  
            int age = ini.get("happy", "age", int.class);  
            double height = ini.get("happy", "height", double.class);  
            String dir = ini.get("happy", "homeDir");  
              
            System.out.println(age);   
            System.out.println(height);  
            System.out.println(dir);  
        }  
      
    }    


被操作文件:

[plain] view plain copy

    [happy]  
    age = 99  
    height = 77.66  
    homeDir = /home/happy  

 

posted @ 2017-09-25 10:59  Tim&Blog  阅读(633)  评论(0编辑  收藏  举报