package your.txtsdka;import java.io.File;import java.util.ArrayList;import java.util.HashMap;import android.app.Activity;import android.os.Bundle;import android.os.Environment;import android.util.Log;import android.widget.ListView;import android.widget.SimpleAdapter;public class Txt_sdkaActivity extends Activity {private ListView lv;ArrayList name;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);lv = (ListView) findViewById(R.id.lv);name = new ArrayList();if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {File path = Environment.getExternalStorageDirectory();// 获得SD卡路径// File path = new File("/mnt/sdcard/");File[] files = path.listFiles();// 读取getFileName(files);}SimpleAdapter adapter = new SimpleAdapter(this, name, R.layout.sd_list,new String[] { "Name" }, new int[] { R.id.txt_tv });lv.setAdapter(adapter);for (int i = 0; i < name.size(); i++) {Log.i("zeng", "list.  name:  " + name.get(i));}}private void getFileName(File[] files) {if (files != null) {// 先判断目录是否为空,否则会报空指针for (File file : files) {if (file.isDirectory()) {Log.i("zeng", "若是文件目录。继续读1" + file.getName().toString()+ file.getPath().toString());getFileName(file.listFiles());Log.i("zeng", "若是文件目录。继续读2" + file.getName().toString()+ file.getPath().toString());} else {String fileName = file.getName();if (fileName.endsWith(".txt")) {HashMap map = new HashMap();String s = fileName.substring(0,fileName.lastIndexOf(".")).toString();Log.i("zeng", "文件名txt::   " + s);map.put("Name", fileName.substring(0,fileName.lastIndexOf(".")));name.add(map);}}}}}}


更多相关文章

  1. sd卡相关
  2. Android(安卓)Studio 各个依赖包存放目录
  3. Android工程打包
  4. [置顶] Android——4.2.2 文件系统目录分析
  5. Android(安卓)VideoView简单播放视频
  6. Android的android.os.DeadObjectException异常
  7. android下面res目录使用
  8. android获取各种系统路径的方法
  9. 细数Android(安卓)Bug

随机推荐

  1. Android P ActivityManagerService(六) sta
  2. android PreferenceActivity使用
  3. Android中英文语言切换
  4. ffmpeg支持android硬件解码mediacodec
  5. 六步骤开发和发布自己的Android Studio类
  6. android 横竖屏等设置
  7. android handle ui 更新
  8. android中获取字符串的宽度
  9. Application Fundamentals--Application
  10. android中网页中的返回功能