zoukankan      html  css  js  c++  java
  • Study Java in application

        It's a long time from my last Java program, for I usually work using C/C++/Objective-C. In this week, I decide to deal with my data from experiment. There are so many data files and it is a depressing work to turn them into a usable format. So I decide to review Java and write some small programs to help me. At first, I try to rename my data files in order to make them simple.

        Data files are in "data" directory with names like "《2006_6》数据.XLS". And I just want them like "2006_6.xls".

     To achieve my point, Regular Expressions and File operations are used. Regular expressions are used for getting new file names from old ones.

    1 import java.io.File;
    2 import java.util.regex.*;
    3
    4 //Get Old file names
    5 File dir = new File("data"); //"data" are the directory where I store my data files
    6 String[] files = dir.list();
    7
    8 File old_name = null;
    9 File new_name = null;
    10
    11 Pattern pattern = new Pattern.compile("[0-9]+_[0-9]+");
    12
    13 for(String file : files)
    14 {
    15 Matcher matcher = pattern.matcher(file);
    16 matcher.find();
    17 old_name = new File(dir, file);
    18 new_name = new File(dir, matcher.group().concat(".xls"));
    19
    20 old_name.renameTo(new_name);
    21 }

    Now, I can batch renaming my data files for next step.

  • 相关阅读:
    禅道安装
    logstash将配置写在多个文件
    原版Filebeat+ELK
    Filebeat+ELK部署文档
    A-2---Jenkins安装
    Linux ftp服务器搭建
    linux 网络命令
    yum安装时出现No more mirrors to try.
    kvm 修改虚拟机密码
    NFS安装
  • 原文地址:https://www.cnblogs.com/jsxh/p/1940751.html
Copyright © 2011-2022 走看看