zoukankan      html  css  js  c++  java
  • Android 扫描Scard卡全部的图片

    1. 这几天为了扫描Scard卡全部的图片的事非常纠结,我原本以为这是一件非常easy的事。可是我发现我错了。网上也没有完整的代码。仅仅是零零碎碎的能扫描单个文件的代码。在今天代码调试通过之后,我认为我有必要和大家分享一下。
      1、因为是手机端的扫描,所以最好开个线程。在子线程中把扫描工作完毕这是很重要的,那么如今開始来看这个类吧!这个代码能够扫描出SCARD卡上全部的文件。


    1. public class GetFilePathThread implements Runnable {
    2.         
    3.         public String pathString;
    4.         public List<String> listpath;
    5.         public GetFilePathThread(String path,List<String> list) {
    6.             this.pathString=path;
    7.             this.listpath=list;
    8.         }
    9.         
    10.         public void run() {

    11.             File file=new File(pathString);
    12.             if (file.isDirectory()) {
    13.                 File fs[]=file.listFiles();
    14.                 if(fs!=null) {
    15.                     System.out.println("文件夹里面包括的全部文件个数--->"+fs.length);
    16.                     if (fs.length>0) {
    17.                         for(int i=0;i<fs.length;i++) {
    18.                             if (fs[i].isFile()) {
    19.                                 listpath.add(fs[i].getAbsolutePath());
    20.                                 System.out.println("文件的绝对路径---->"+fs[i].getAbsolutePath());
    21.                             } else if (fs[i].isDirectory()) {
    22.                                 System.out.println("文件夹的绝对路径---->"+fs[i].getAbsolutePath()+"/");
    23.                                 new Thread(new GetFilePathThread(fs[i].getAbsolutePath()+"/", listpath)).start();
    24.                              //    getFilePath(fs[i].getAbsolutePath(),listpath);
    25.                                  
    26.                             }
    27.                         }
    28.                     }
    29.                 }
    30.             }
    31.         }
    32.     }


    2、扫描出我们所须要的图片文件,当然在这之前要先定义
    private List list=new ArrayList();



    1. StringBuffer buffer=new StringBuffer();
    2.                 for(int i=0;i<list.size();i++) {
    3.                     if (list.get(i).endsWith(".jpg")) {
    4.                         buffer.append(list.get(i).toString()+"n");
    5.                     }
    6.                 }

    3、记得增加关于Scard卡的读写权限。这个非常重要。至于开启线程的事,我就不多说了 。


    总结:这次代码在小地方纠结了非常久,真的非常不应该。主要问题是两个,一个是怎么遍历目录下的子文件,第二,怎么获取加入进去的文件路径;
    希望这些能对大家实用!

  • 相关阅读:
    字符编码相关
    函数之形参与实参
    文件操作模式
    函数对象,名称空间,作用域,和闭包
    吴裕雄天生自然SPRINGBOOT开发实战处理'spring.datasource.url' is not specified and no embedded datasource could be autoconfigured
    吴裕雄天生自然SPRINGBOOT开发实战处理XXXX that could not be found.
    吴裕雄天生自然SPRINGBOOT开发实战SpringBoot HTML表单登录
    吴裕雄天生自然SPRINGBOOT开发实战SpringBoot REST示例
    吴裕雄天生自然SpringBoot开发实战学习笔记处理 Could not write metadata for '/Servers'.metadata\.plugins\org.eclipse.core.resources\.projects\Servers\.markers.snap (系统找不到指定的路径。)
    吴裕雄天生自然SPRINGBOOT开发实战SpringBoot Tomcat部署
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6868723.html
Copyright © 2011-2022 走看看