从ApplicationResources.properties中读取数据对文件进行操作.java

package com.wyebd.recruit.filegetter;

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

import com.wyebd.publicuse.ApplicationResource;

public class SkFileGetter extends FileGetterCom{

 public void copyFiles()
 {

//  String pathast="D:/yb/station";
//  String pathastout="D:/ybcopy/station/astadata.txt";
  String pathast=ApplicationResource.getValueByKey("pathast");
  String pathastout=ApplicationResource.getValueByKey("pathastout");
  boolean allfilenames=false;
  try{

 
   File fileast=new File(pathast);
   
   boolean astname=getAllName(pathast,pathastout,fileast);
   
   if(astname)
   {
    allfilenames=true;
   }
   
   System.out.println("allfilenames==::"+allfilenames);
   System.out.println("****************************************");
   
  }catch(Exception e)
  {
   e.printStackTrace();
  }
  finally
  {
   if(allfilenames)
   {
    setFile(pathastout);
   }
  }

   
 }
 public boolean getAllName(String path,String pathout,File file)
 {
  boolean boon=false;
  if(file.exists())
  {

   String filename=getLstModName(file,path);
   System.out.println("filename==::"+filename);
   if(!(filename.equals("")))
   {
    boolean bool=readAndWrite(path+"/"+filename,pathout,filename);
    System.out.println("bool==::"+bool);
    if(bool)
    {
     boon=true;

    }
   }
   
  }
  return boon;
 }
 public String getLstModName(File filezwx,String path)
 {
  String[] fileList=filezwx.list();
 
  String filename="";
  long tempModTime=0;
  for(int i=0;i<fileList.length;i++)
  {
   if(check(fileList[i]))
   {
//    System.out.println("fileList[i]==::"+fileList[i]);
    File filesubzwx=new File(path+"/"+fileList[i]);
//    System.out.println("filesubzwx==::"+filesubzwx);
    if(tempModTime==0)
    {
     tempModTime=filesubzwx.lastModified();
     filename=fileList[i];
//     System.out.println("tempModTime==::"+tempModTime);
    }
    else
    {
     int num=comparMod(tempModTime,filesubzwx.lastModified());
     if(num==1)
     {
      tempModTime=filesubzwx.lastModified();
      filename=fileList[i];
//      System.out.println("tempModTime==::"+tempModTime);
      
     
     }
    }
   }

   
  }
  
  return filename;
 }
 public boolean readAndWrite(String srcpath,String inputpath,String filenames)
 {
  boolean sign=false;
  File file=new File(srcpath);
  File fileOut=new File(inputpath);
  if(!(fileOut.exists()))
  {
   try{
    fileOut.createNewFile();
    
   }catch(Exception e)
   {
    e.printStackTrace();
   }

  }
//  System.out.println("file==:::"+file);
  if(file.exists())
  {
//   System.out.println("file==:::"+(file.getName()));
   try{
    
    FileInputStream fis=new FileInputStream(file);
    FileOutputStream fos=new FileOutputStream(fileOut);
    
    FileChannel fc=fis.getChannel();
    FileChannel tc=fos.getChannel();
    fc.transferTo(0,fc.size(),tc);
    
    fis.close();
    fos.close();
    fc.close();
    tc.close();
    sign=true;
    
   }catch(Exception e)
   {
    e.printStackTrace();
   }
   
 
   
  }
  
  return sign;
 }
 public boolean check(String name)
 {
  boolean sign=false;
  if(name!=null)
  {
   String headOfName=name.substring(0,6);
   System.out.println("headOfName==::"+headOfName);
   
   if(headOfName.compareTo("BJAWS_")==0)
   {
    String[] nameArr=name.split("[.]");

    if(nameArr.length==2&&((nameArr[1].equals("txt"))||(nameArr[1].equals("TXT"))))
    {
     
     String[] timeArr=nameArr[0].split("_");
     if(timeArr.length==2&&(timeArr[1].length()==14))
     {
      sign=true;
     }
     
    }
   }

  }

  
  return sign;
 }
 
 
 public int comparMod(long strtime,long time)
 {
  int i=-1;
  if(strtime<time)
  {
   i=1;
  }
  return i;
 } 
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO 自动生成方法存根
//  (new SkFileGetter()).copyFiles();
  System.out.println((new SkFileGetter()).getFile());
 }

}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值