android读取plist文件

ios的配置文件是写在.plist里。
那么,如何从android读取.plist文件内容呢?
1.需要导入dd-plist.jar
2.读取.plist文件


config.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>version</key>
	<integer>1</integer>
	<key>net</key>
	<dict>
		<key>http</key>
		<dict>
			<key>timeout</key>
			<integer>30</integer>
			<key>URL</key>
			<string>http://xxx.xxx.xxx.xxx</string>
			<key>certifyUser</key>
			<dict>
				<key>URL</key>
				<string>http://xxx.xxx.xxx.xxx/certifyUser</string>
				<key>encoding</key>
				<string>utf-8</string>
			</dict>
		</dict>
	</dict>
</dict>
</plist>



逻辑方法
URL url = null;
InputStream in = null;
in = XmlUtil.getFileInputStream( "config/config.plist", context );
NSDictionary configSetting = (NSDictionary) PropertyListParser.parse( in );
NSDictionary configNet = (NSDictionary) configSetting.objectForKey( "net" );
NSDictionary configHttp = (NSDictionary) configNet.objectForKey( "http" );
String strUrl = configHttp.objectForKey( "URL" ).toString();
url = new URL( strUrl );


XmlUtil中的方法
public static InputStream getFileInputStream( String fileName, Context context ) {

    AssetManager am = context.getResources().getAssets();
    InputStream in = null;
    try {
        in = am.open( fileName );
    } catch ( IOException e ) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return in;
}

你可能感兴趣的:(java,android,plist,dd-plist)