---
title: "android读取plist文件"
author: "xushans"
date: "2015-06-30T14:09:40Z"
tags: ["Android", "Java", "plist"]
categories: ["移动开发"]
slug: "android-plist"
draft: false
lastmod: "2015-06-30T14:12:52Z"
id: 2223102
url: "https://xushans.iteye.com/blog/2223102"
---

ios的配置文件是写在.plist里。 那么，如何从android读取.plist文件内容呢？ \[b]1.需要导入dd-plist.jar 2.读取.plist文件\[/b] config.plist \[code="xml"] version 1 net http timeout 30 URL http://xxx.xxx.xxx.xxx certifyUser URL http://xxx.xxx.xxx.xxx/certifyUser encoding utf-8 \[/code] 逻辑方法 \[code="java"] 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 ); \[/code] XmlUtil中的方法 \[code="java"] 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; } \[/code]