Android中如何获取asset目录下的ini文件
来源:互联网 发布:淘宝美女卖内衣的视频 编辑:程序博客网 时间:2024/05/21 10:28
1、获取资源的输入流
假设资源位于assets目录下:
Context.getAssets().open(“sample.txt”) ;
public void deepFile(Context ctxDealFile, String path) {
try {
String str[] = ctxDealFile.getAssets().list(path);
if (str.length > 0) {// 如果是目录
File file = new File("/data/" + path);
file.mkdirs();
for (String string : str) {
path = path + "/" + string;
System.out.println("zhoulc:\t" + path);
// textView.setText(textView.getText()+"\t"+path+"\t");
deepFile(ctxDealFile, path);
path = path.substring(0, path.lastIndexOf('/'));
}
} else {// 如果是文件
InputStream is = ctxDealFile.getAssets().open(path);
FileOutputStream fos = new FileOutputStream(new File("/data/"
+ path));
byte[] buffer = new byte[1024];
int count = 0;
while (true) {
count++;
int len = is.read(buffer);
if (len == -1) {
break;
}
fos.write(buffer, 0, len);
}
is.close();
fos.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
2、具体例子
private void getBootUrl(Context context) throws IOException {
Log.d(TAG, "getBootUrl() start");
InputStream is = null;
BufferedReader in = null;
try {
is = context.getAssets().open("ini/boot.ini");
in = new BufferedReader(new InputStreamReader(is));
} catch (IOException e1) {
e1.printStackTrace();
Log.d(TAG, e1.getMessage());
}
StringBuffer sb = new StringBuffer();
String temp = null;// 存放每行读取的内容
int line = 1;
String[] sbStrs = new String[] {};// 以“=”为分隔符将string分割
try {
while ((temp = in.readLine()) != null) {
if (temp.contains("boot")) {
sb.append(temp.substring((temp.indexOf("t") + 2)) + " ");// 从“=”等分隔符以后截取子串保存,即只保存了boot和bootIp
line++;
// 读取下一行
while ((temp = in.readLine()) != null) {
if (temp.contains("bootIP")) {
sb.append(temp.substring((temp.indexOf("P") + 2))
+ " ");// 从“=”等分隔符以后截取子串保存,即只保存了boot和bootIp
break;
} else {
line++;
}
}
break;
}
}
in.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
bootUrl = "";
Log.d(TAG, e.getMessage());
} finally {
if (in != null) {
in.close();
}
}
sbStrs = sb.toString().split(" ");
bootUrl = sbStrs[0];
bootIpUrl = sbStrs[1];
Log.d(TAG, "getBootUrl() end");
}
- Android中如何获取asset目录下的ini文件
- Android如何获取asset目录下所有文件的路径
- Android如何获取asset下的xml文件,并解析
- 如何访问android的asset目录和res目录下的文件
- 如何访问android的asset目录和res目录下的文件
- 如何访问android的asset目录和res目录下的文件
- 如何访问android的asset目录和res目录下的文件
- Android复制asset目录的文件到SD卡下
- Android复制asset目录的文件到SD卡下
- 获取当前工程目录下的ini文件方法
- 获取当前工程目录下的ini文件方法
- android中读取asset文件夹下的文件
- Android中安装asset文件下的apk
- java中如何获取项目各个目录下的文件
- 在javaEE中如何获取SCR目录下的文件
- java中如何获取项目各个目录下的文件
- java中如何获取项目各个目录下的文件
- 获取Android “/asset”目录数据
- MySQL JDBC driver jar下载问题
- iOS错误:duplicate symbol _OBJC_METACLASS_$_ClassName
- javascript/JS限制用户名只能输入字母和数字下划线
- 企业信息系统安全的生命周期
- iOS 自定义类,使其可以在IB中渲染,并在inspector中修改属性
- Android中如何获取asset目录下的ini文件
- Js操纵iframe中Dom以及iframe子页面中Js操纵父页面Dom
- LOOP & HANDLE
- Android开发之自定义圆形的ImageView的实现
- HDU 5135 Little Zu Chongzhi's Triangles(贪心)
- UEditor 1.4.3 jsp配置
- 社会化海量数据采集爬虫框架搭建
- 初学遇到的问题
- appNotResponding()分析