android asset 目录,Android如何获取asset目录下所有文件的路径

package com.hangcheng.util;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import android.app.Activity;

import android.content.Context;

import android.content.res.AssetManager;

public class GetfilesFromAssets {

private Activity activity;

private String[] files;

public GetfilesFromAssets(Context context) {

this.activity = (Activity) context;

}

// 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();

// }

// }

public String[] getfileFromAssets(String path) {

AssetManager assetManager = activity.getAssets();

// String[] files;

try {

files = assetManager.list(path);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return files;

}

public List listHtmlOfAssets() {

List list = new ArrayList();

files = getfileFromAssets("html");

for (int i = 0; i < files.length; i++) {

HashMap map = new HashMap();

map.put("htmlname", files[i]);

list.add(map);

}

return list;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值