批量修改文件名称

package mp3;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class UpdateFileName {
public static void updateName() throws Exception{
String path="F:\\电子书\\三国演义\\评书:袁阔成_三国演义\\三国演义";
String outPath="F:\\电子书\\三国演义\\评书:袁阔成_三国演义\\转换名称";
File files=new File(path);
System.out.println(files.exists() );
System.out.println(files.isDirectory());
FileInputStream inputStream=null;
FileOutputStream outputStream=null;
FileChannel  inChannel=null;
FileChannel  outChannel=null;
if(files.exists() && files.isDirectory()){
  File[]  arrys =files.listFiles();
  for (int i = 0; i < arrys.length; i++) {
  File file=arrys[i];
  String fileName=file.getName();
  System.out.println("正在处理的文件为:"+fileName);
  String newFileName=fileName.substring(19, fileName.length());
  inputStream=new FileInputStream(file);
  outputStream=new FileOutputStream(new File(outPath+File.separator+newFileName));
  inChannel=inputStream.getChannel();
  outChannel=outputStream.getChannel();
  inChannel.transferTo(0, inChannel.size(), outChannel);
  }
}
inputStream.close();
outputStream.close();
}
public static void main(String[] args) throws Exception {
UpdateFileName.updateName();

}
}







                       @dianxinxinxiyuan.xiuyanxilu.pudongqu.shanghhai   2014-09-04

你可能感兴趣的:(批量修改文件名称)