Android 读取OTG中配置文件完成自动测试

版权声明:本文原创,转载请注明出处:http://blog.csdn.net/zhoumushui https://blog.csdn.net/zhoumushui/article/details/51537682

Config文件格式:

#版本号
Version=Android_20160530
#供搜索的Wifi热点名
WifiAPssid=Network
#Wifi最低Rssi(dBm)
WifiMinRssi=-95
#供搜索的蓝牙名称
BTDeviceName=AZ
#电池最低电压(mV)
BatteryLevelL=3200
#电池最高电压(mV)
BatteryLevelH=4410
#USB存储器最低可用容量(MB)
NandFlashL=5000
#USB存储器最高可用容量(MB)
NandFlashH=5500

读取:

		// Read CondorConfig.ini file
		SharedPreferences sharedPreferences = getSharedPreferences(
				"CondorConfig", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		try {
			String encoding = "utf-8";
			File fileConfig = new File("/storage/usbotg/Config.ini");
			if (fileConfig.isFile() && fileConfig.exists()) { // 判断文件是否存在
				InputStreamReader read = new InputStreamReader(
						new FileInputStream(fileConfig), encoding);// 考虑到编码格式
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineText = null;
				while ((lineText = bufferedReader.readLine()) != null) {
					if (!lineText.startsWith("#")) {
						if (lineText.trim().length() > 0) {
							String[] arrayLine = lineText.split("=");
							String key = arrayLine[0];
							String value = "";
							if (arrayLine.length == 2) {
								value = lineText.split("=")[1];
							}
							Log.v("AZ", "Key:" + key + ",Value:" + value);
							editor.putString(key, value);
							editor.commit();
						}
					}
				}
				read.close();
			} else {
				Log.e("AZ", "No such file.");
			}
		} catch (Exception e) {
			Log.e("AZ", "Read file catch Exception:" + e.toString());
			e.printStackTrace();
		}


阅读更多

没有更多推荐了,返回首页