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());
}
}