给定路径得到本路径下文件夹以及所有文件的列表排序问题

2015年01月12日 其他资源 13条评论 阅读3604次

给定路径得到本路径下文件夹以及所有文件的列表排序问题

本文主要解决的是排序问题:也就是给定路径下要求,文件夹在前文件在后,并且按照数字字母先后顺序排列

private List<File> getFileList(String path) {

        final String ROOT = Environment.getExternalStorageDirectory()
                .toString();
        List<File> fileList = new ArrayList<File>();

        File topFile = new File(path);
        for (File file : topFile.listFiles()) {
            fileList.add(file);
        }

        Collections.sort(fileList, new Comparator<File>() {
            @Override
            public int compare(File o1, File o2) {
                if (o1.isDirectory() && o2.isFile()) {
                    // 文件夹在文件的前面
                    return -1;
                }
                if (o1.isFile() && o2.isDirectory()) {
                    // 文件在文件夹的后面
                    return 1;
                }
                // 同为文件或同为文件夹,a-z、0-9的顺序排列
                // 因为compareTo是按照ASCII码排序,所以忽略大小写,统一用小写字母
                return -(o2.getName().toLowerCase().compareTo(o1.getName()
                        .toLowerCase()));
            }
        });

        if (path != ROOT) {
            // if the current path is not ROOT_PATH, add ../ at the first
            fileList.add(0, new File(path).getParentFile());
        }

        return fileList;
    }
分享本文至:

WRITTEN BY

avatar
本文标签:排序sort
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

13 条评论

  1. <a href="http://www.onewebsql.net/adidas-ultra-boost-hvid-pre-order-butyf">adidas ultra boost hvid pre order</a> <a href="http://www.onlinne.net/asics-gel-quantum-360-knit-wei%C3%9F-glove-scarpec">asics gel quantum 360 knit wei脽 glove</a> <a href="http://www.onpointsports.net/air-max-zero-night-maroon-atomic-rosa-nation-chaussuresf">air max zero night maroon atomic rosa nation</a> <a href="http://www.oqibo.net/nike-shox-turbo-for-salg-butya">nike shox turbo for salg</a> <a href="http://www.ourjourneychurch.net/roshe-run-dark-bleu-and-vert-schuhea">roshe run dark bleu and vert</a> <a href="http://www.ouverturefacile.net/jordan-retro-1-bianca-blu-schuhec">jordan retro 1 bianca blu</a>
    powersoak http://www.powersoak.net/

  2. avatar tumpuanlar

    <a href="http://www.assistobot.com/nike-roshe-run-r%C3%B8d-hyperfuse-laser-crimson-scarpeg">nike roshe run r酶d hyperfuse laser crimson</a> <a href="http://www.azhomereports.com/ua-clutchfit-drive-plata-amarillo-kurpesf">ua clutchfit drive plata amarillo</a> <a href="http://www.chieao.com/adidas-tubular-runner-marron-hair-schuheg">adidas tubular runner marron hair</a> <a href="http://www.dpotimeshare.com/nike-free-run-5.0-v4-bianca-leopard-print-schuheb">nike free run 5.0 v4 bianca leopard print</a> <a href="http://www.enhancingarpu.com/nike-air-max-express-gris-and-rouge-chaussurese">nike air max express gris and rouge</a> <a href="http://www.myflipsstore.com/nike-zoom-hyperrev-2015-bianca-film-butyg">nike zoom hyperrev 2015 bianca film</a>
    tumpuanlar http://www.tumpuanlar.com/

  3. avatar 7x8rq331

    <a href="http://www.suopbhi0.com/air-jordan-1-mid-baskets-butye">air jordan 1 mid baskets</a> <a href="http://www.rpus144x.com/hommes-asics-gel-kinsei-4-bleu-ciel-violet-butya">hommes asics gel kinsei 4 bleu ciel violet</a> <a href="http://www.064eaffu.com/herre-salomon-gcs-athletic-trail-r%C3%B8d-lyser%C3%B8d-obuvb">herre salomon gcs athletic trail r酶d lyser酶d</a> <a href="http://www.2g9s16lv.com/nike-blazer-alle-schwarz-leder-scarpec">nike blazer alle schwarz leder</a> <a href="http://www.waxhq23s.com/femminile-new-balance-420-royal-blu-schuhef">femminile new balance 420 royal blu</a> <a href="http://www.2pdyrpwy.com/nike-classic-cortez-fonctionnement-chaussures-scarpec">nike classic cortez fonctionnement chaussures</a>
    7x8rq331 http://www.7x8rq331.com/

  4. avatar voilahalla

    <a href="http://www.arsindustrialis.net/nike-kobe-11-tutti-verde-schuhea">nike kobe 11 tutti verde</a> <a href="http://www.avscience.net/nike-zoom-clear-out-rouge-rose-chaussuresa">nike zoom clear out rouge rose</a> <a href="http://www.babyblend.net/nike-free-run-3-5.0-mujeres-amarillo-gris-obuva">nike free run 3 5.0 mujeres amarillo gris</a> <a href="http://www.bancoideas.net/nike-air-max-90-bambini-blu-grigio-butyc">nike air max 90 bambini blu grigio</a> <a href="http://www.barcosquecantan.net/yeezy-350-boost-triple-sort-girl-scarpeb">yeezy 350 boost triple sort girl</a> <a href="http://www.benefitsnw.net/flyknit-lunar-1-gr%C3%A5-bl%C3%A5-and-hvit-kurpesf">flyknit lunar 1 gr氓 bl氓 and hvit</a>
    voilahalla http://www.voilahalla.net/

  5. avatar golfbodyshop

    <a href="http://www.bhcsboosters.com/nike-free-run-3-blue-grey-skof">nike free run 3 blue grey</a> <a href="http://www.denisgoulart.com/nike-free-run-3-womens-running-shoes-hot-punch-pink-skob">nike free run 3 womens running shoes hot punch pink</a> <a href="http://www.donggeomdo.com/jordan-hats-2017-update-hata">jordan hats 2017 update</a> <a href="http://www.ozoessaouira.com/air-jordan-14-green-jordan-4-runninge">air jordan 14 green jordan 4</a> <a href="http://www.annomaplexel.com/nike-kaishi-rojo-verde-schuhea">nike kaishi rojo verde</a> <a href="http://www.bringribben.com/air-jordan-retro-1-kvinders-gr%C3%B8n-himmelbl%C3%A5-scarpeb">air jordan retro 1 kvinders gr酶n himmelbl氓</a>
    golfbodyshop http://www.golfbodyshop.com/

  6. avatar hrubinlaser

    <a href="http://www.mikespothole.com/new-york-yankees-cap-egypt-game-hata">new york yankees cap egypt game</a> <a href="http://www.theclaydoctor.com/orange-mens-new-balance-1500-runninge">orange mens new balance 1500</a> <a href="http://www.allthatspool.com/air-jordan-7-hvit-infrar%C3%B8d-svart-verde-schuhea">air jordan 7 hvit infrar酶d svart verde</a> <a href="http://www.ihavewed.com/mujeres-asics-gel-noosa-tri-10-naranja-verde-scarpeb">mujeres asics gel noosa tri 10 naranja verde</a> <a href="http://www.cloudsmartin.com/womens-nike-internationalist-red-italy-shoeso">womens nike internationalist red italy</a> <a href="http://www.myachingoa.com/jordan-6-infrarosso-23-grade-school-kurpesb">jordan 6 infrarosso 23 grade school</a>
    hrubinlaser http://www.hrubinlaser.com/

  7. avatar fabloomsilk

    <a href="http://www.heslaatours.com/cheap-air-jordan-after-game-womens-silver-runninge">cheap air jordan after game womens silver</a> <a href="http://www.prostekrasna.com/air-jordan-retro-3-negro-and-blanco-schuhea">air jordan retro 3 negro and blanco</a> <a href="http://www.altharmony.com/nike-lebron-13-dam%C3%A4nner-silber-blau-scarpeb">nike lebron 13 dam盲nner silber blau</a> <a href="http://www.cosmicupcake.com/nike-air-max-95-green-spain-shoeso">nike air max 95 green spain</a> <a href="http://www.btmtecled.com/nike-air-force-1-ultra-force-mid-joli-femmes-chaussure-kurpesb">nike air force 1 ultra force mid joli femmes chaussure</a> <a href="http://www.torcgunstore.com/nike-mercurial-vapor-x-fg-grey-black-pink-zapatost">nike mercurial vapor x fg grey black pink</a>
    fabloomsilk http://www.fabloomsilk.com/

  8. avatar 5my463sz

    <a href="http://www.5tqkyfya.com/adidas-prossoator-absolado-instinct-lz-schuhed">adidas prossoator absolado instinct lz</a> <a href="http://www.1v9ssaoa.com/asics-gel-kinsei-5-marr%C3%B3n-amarillo-butye">asics gel kinsei 5 marr贸n amarillo</a>
    [url=http://www.5my463sz.com/]5my463sz[/url]

  9. avatar h732y4ki

    <a href="http://www.febrsjsq.com/lebron-14-university-rot-schwarz-and-wei%C3%9F-game-scarped">lebron 14 university rot schwarz and wei脽 game</a> <a href="http://www.eh440fwo.com/zx-flux-oransje-svart-obuvc">zx flux oransje svart</a> <a href="http://www.yz413tae.com/nike-air-jordan-ajf-4-premier-sort-varsity-r%C3%B8d-stealth-chaussuresg">nike air jordan ajf 4 premier sort varsity r酶d stealth</a> <a href="http://www.kojqfbo6.com/herren-nike-lunarglide-7-schwarz-gr%C3%BCn-chaussuresa">herren nike lunarglide 7 schwarz gr眉n</a> <a href="http://www.eax5s1up.com/adidas-rose-773-basketbtout-chaussures-hommes-butya">adidas rose 773 basketbtout chaussures hommes</a> <a href="http://www.iumtx7cb.com/nike-internationalist-summit-hvid-obsidian-new-slate-butyd">nike internationalist summit hvid obsidian new slate</a>
    h732y4ki http://www.h732y4ki.com/

  10. avatar 王语双

    外行路过,留一爪印,闪人。

  11. avatar 威客

    现在做安卓的越来越多

  12. avatar Han

    安卓主流现在已成定局

欢迎留言




用户登录

sitemap