Chinaunix首页 | 论坛 | 博客
  • 博客访问: 365480
  • 博文数量: 1051
  • 博客积分: 53280
  • 博客等级: 大将
  • 技术积分: 6670
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 13:21
文章分类

全部博文(1051)

文章存档

2011年(1)

2008年(1050)

我的朋友

分类:

2008-09-09 16:48:57

        import java.io.File;
        import java.util.*;
        import java.sql.Date;
        import java.text.DateFormat;
        import java.text.SimpleDateFormat;
        import java.text.NumberFormat;
        /**
        * Created by IntelliJ IDEA.

        * User: leizhimin

        * Date: 2008-7-18 22:02:30

        * Note: 模拟dir测试的例程
        */
        public class TestFile {
            public static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            int nl = 18;
            public static void main(String args[]) {
                test();
            }
            public static void test() {
                System.out.println("----------test()----------");
                File file = new File("F:\\SOFT_DEV");
        //        file.isDirectory();
        //        System.out.println(File.pathSeparator);
        //        System.out.println(File.pathSeparatorChar);
        //        System.out.println(File.separator);
        //        System.out.println(File.separatorChar);
                FileComparator fc = new FileComparator();
                File[] lf = file.listFiles();
                Arrays.sort(lf, fc);    //数组排序
                for (File f : lf) {
                    String dataStr = df.format(new Date(f.lastModified()));

                    if (f.isDirectory()) {
                        System.out.print(dataStr + " 

       ");

                    } else {
                        System.out.print(dataStr + "  " + getFormatString(String.valueOf(NumberFormat.getInstance().format(f.length()))));
                    }
                    System.out.println("  " + f.getName());
                }

            }
            //格式化函数
            public static String getFormatString(String s) {
                int nb = 12 - s.length();
                StringBuilder sb = new StringBuilder();
                if (nb > 0) {
                    for (int n = 1; n <= nb; n++) {
                        sb = sb.append(" ");
                    }
                }
                return sb.append(s).toString();
            }
        }


--------------------next---------------------

阅读(147) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~