`

Update mass of file

阅读更多
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class PortChange {

public static int time=0;

public static void main(String[] args){
   String fileName="E:\\zip";
   String fileType=".xml";
   iteratorFile(fileName,fileType,"","");
   System.out.println("一共更新了"+time+"个文件");
}

public static void iteratorFile(String fileName,String fileType,String from,String to){
   File file=new File(fileName);
   File[] files=file.listFiles();
   for(int i=0;i<files.length;i++){
    if(files[i].isDirectory()){
     iteratorFile(files[i].getAbsolutePath().replace('\\','/'),fileType,from,to);
    }else if(files[i].isFile()){
     String file_name=files[i].getAbsolutePath().replace('\\','/');
     updateFile(new File(file_name),fileType,from,to);
    }
   }
}

public static void updateFile(File file,String fileType,String from,String to){
   if(file.getName().length()>4&&file.getName().substring(file.getName().length()-4).equals(fileType)){
   try {
    int index=file.getAbsolutePath().lastIndexOf('\\')+1;
    String fileName=file.getName();
    File file1=new File(file.getAbsolutePath().substring(0,index)+fileName+"_bakj");
    System.out.println(file.getAbsolutePath());
    BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1)));
    String line=null;
    while((line=br.readLine())!=null){
    // bw.write(line.replace("charset=gb2312", "charset=gbk").replace("charset=GB2312","charset=gbk")+"\n");
   //  bw.write(line.replace("<Connector port=\"8080\"", "<Connector port=\"8888\""));
     bw.write(line.replace("<Connector port=\""+from+"\"", "<Connector port=\""+to+"\""));
    }
    time++;
    bw.flush();
    bw.close();
    br.close();
    file.delete();
    file1.renameTo(new File(file.getAbsolutePath().substring(0,index)+fileName));
   } catch (FileNotFoundException e) {
    e.printStackTrace();
   } catch (IOException e) {
    e.printStackTrace();
   }
   }
}
}
分享到:
评论

相关推荐

    Mask 98 for PRwin98

    with the ability to update the visual appearance of Windows 3.x with that of the more attractive Windows 95/98 3-D styles, including menus, windows and desktop. It carries this out using unique 'Run-...

    USB_LocalDisk

    9.Now, on line 26 of the cfadisk.inf file, after the comma, delete the text: device_instance_id_goes_here and then press ctrl+v to paste the text from step 8 into the section. For example, my line 26 ...

    NewSID(光学习一下代码就可以了,没看清楚介绍别运行)

    It first generates a random SID for the computer, and proceeds to update instances of the existing computer SID it finds in the Registry and in file security descriptors, replacing occurrences with ...

    Salesforce批量编辑器「Salesforce Mass Editor」-crx插件

    ・Mass insert, mass clone, mass update and mass delete. ・Mass copy & paste from Excel with multiple rows and cells data. ・Export list view data to CSV file. If you have any question or issue, report...

    BPI+FLASH配置MicroBlaze软核总结

    1. 利用 XPS 将 FPGA 逻辑和 bootloader 程序整合在一起 打开 XPS,选择菜单栏 Device Configuration –&gt; Update Bitstream,结果为工程存放路径下 implementation 文件夹中的 download.bit 文件。 2. 将 download....

    a project model for the FreeBSD Project.7z

    Committers fall into three groups: committers who are only concerned with one area of the project (for instance file systems), committers who are involved only with one sub-project and committers who ...

    simple-tags

    * Externalize options array on external file for diminue memory consommation. (call only on options page) * Fix importers embedded tags * Version 1.7.2 : * Add taxonomy support * Rewrite manage ...

    SIMPACK上机建模指导[整理].pdf

    然后双击 $B_wheelset1 ,在窗口中定义质量、重心、惯性矩等参数,并选择 center of mass 类型。然后按 3D geometry 按钮,定义几何形状,在窗口中选择 $B_wheelset1_cuboid ,按 modify 按钮,选择 type 为 ...

    UG6.0快捷键大全

    Unigraphics Modeling Application Menu File ! ! ! VERSION 120 UG6.0 ! *************** Changes to the Menubar itself *************** EDIT UG_GATEWAY_MAIN_MENUBAR ! *************** Format Menu *****...

    Laravel开发-laravel-db-language

    模型类中的`$table`属性用于指定模型对应的数据库表名,而`$fillable`或`$guarded`属性则用于控制数据填充的安全性,防止Mass Assignment漏洞。`$fillable`定义了允许批量赋值的字段,而`$guarded`则定义了需要排除...

    Software Testing and Continuous Quality Improvement

    27 vii &lt;br&gt; Software Testing and Continuous Quality Improvement 2 Overview of Testing Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Black-Box Testing (Functional)....

    Laraboot: Laravel 5 For Beginners

    Setup Local Host file: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Vhost Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 ...

    ( ap6181_sina33m_sc3817r验证通过_20170710_1608没有外层目录.7z

    # to observe dnsmasq.leases file for dhcp information of soft ap. chown dhcp system /data/misc/dhcp on post-fs-data mkdir /data/media 0770 media_rw media_rw # bluetooth MAC address programming ...

Global site tag (gtag.js) - Google Analytics