ACM copy

每天都要将自己写得代码复制一遍

房后放在*_d.txt 的文件里

于是 自己做了一个小程序,偷懒


程序功能       ,可以将当前的的java 复制带桌面,但是前提桌面有一个以*_t.txt 文件结尾的文件,


因为每天要发题  所以每一道题都是以_t.txt,结尾  答案是_d.txt  结尾



----------------------------------------

这是源代码

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

/*
 * 实现功能
 * 用用此类,
 * 1 将桌面上没有 *_t.txt  文件  新建成一个     *_d.txt   文件,并将*_t.txt  文件,放置于桌面的ACM 文件夹里
 */
class ACM{
    
}
public class ACMCopy {
    private String path="C:"+File.separator+"Users"+File.separator+"if"+File.separator+"Desktop";
    private File file;
    private String AllInfo="";
    
    public ACMCopy(String str) throws IOException {
        // TODO Auto-generated constructor stub
        file=new File(path);
        fun(str);
    //    System.out.println(getTraceInfo());
    }
    
    
    public void fun(String str) throws IOException{
        File temp[]=file.listFiles();
        
        for(File info:temp)
            this.AllInfo+=info.toString();
        
        for(File info:temp){
            if(is_t(info.toString(),str))
                System.out.println(info.toString());
        }
    }
    //判断 是否 唯一_t.txt
    public  boolean is_t(String info,String str) throws IOException{
        if(info.contains("_t.txt")){
            String temp=info.replaceFirst("_t.txt", "_d.txt");
            if(!this.AllInfo.contains(temp)){
            //    System.out.println("temp_  "+temp);
                create(temp);//创建目标文件
                
            
                
                FunCopy(temp,this.get(str));
                
                return true;
            }
            else
                return false;
        }
        return false;
    }
    //  创建    temp 为_d.txt 的文件
    public void create(String temp) throws IOException{
        File cfile=new File(temp);
        if(!cfile.getParentFile().exists())
            cfile.getParentFile().mkdirs();
        if(!file.exists())
            cfile.createNewFile();
            
    }
    
    
    
    // 复制 数据  当前的数据,当目标文件中
    public void FunCopy(String output,String input) throws FileNotFoundException{
    
        
        PrintStream out=new PrintStream(new FileOutputStream(new File(output)));
        
        Scanner scan=new Scanner(new FileInputStream(new File(input)));
        scan.useDelimiter("\n");
        
        while(scan.hasNext()){
            out.println(scan.next());
        }
        
        out.println("*******************************************************************************");
        out.println("                                 ACMCopy 生成                                                                                                                           ");
        out.println("*******************************************************************************");
        scan.close();
        out.close();
    }
    
    
    
    
    //获取当前类的名字的路径
    
    public String get(String str)
    {
    File file = new File(this.getClass().getResource("/").getPath());
    str="src"+file.separator+str;

    return file.toString().replace("bin",str)+".java";
    }
    
    
    
//    public static void main(String[] args) throws IOException {
//        ACMCopy a=new ACMCopy();
//        //String str="C:"+File.separator+"Users"+File.separator+"if"+File.separator+"Desktop"+File.separator+"中位数_d.txt";
//        //System.out.println(str);
//    /*    String str=getTraceInfo();
//        System.out.println(a.get(str));*/
//        
//        
//        //a.create(str);
//    
//    
//    }
    
    //  获取当前的列.名字
    public static String getTraceInfo(){    
        StringBuffer sb = new StringBuffer();                
        StackTraceElement[] stacks = new Throwable().getStackTrace();    
        int stacksLen = stacks.length;    
        sb.append(stacks[1].getClassName());           
        return sb.toString();    
    }
    


}

------------------------------------------------

这是我的一个答案代码


import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Me{
    private int num[];
    public Me(int num[]) {
        // TODO Auto-generated constructor stub
        Arrays.sort(num);
        this.num=num;
        //System.out.println(this.num.toString());
        System.out.println(this.num[(this.num.length)/2]);
    }
}
public class MeSo {
    public static void main(String[] args) throws IOException {
    /*    Scanner scan=new Scanner(System.in);
        int length=scan.nextInt();
        int temp[]=new int [length];
        for(int i=0;i<length;i++){
            temp[i]=scan.nextInt();
        }

        */
        ACMCopy a=new  ACMCopy(ACMCopy.getTraceInfo());
                
        
    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值