zoukankan      html  css  js  c++  java
  • 创建随机的文件

    package File;
    
    import java.io.IOException;
    
    //创建随机的文件
    public class FileCreade {
        public static void main(String args[]) throws IOException{
            int MaxFile=Integer.parseInt(args[0]);
            String Path=args[1];
    //        int MaxFile=10;
    //        String Path="C:/df/";
            for(int i=0;i<MaxFile;i++){
                int Length=10;
                int LastLength=3;
                String Name=new GreadName(Length).Name;
                String LastName=new GreadName(LastLength).Name;
                String FName=Path+Name+"."+LastName;
                new GreadFile(FName);
            }
        }
    }
    package File;
    
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    
    public class GreadFile {
        public GreadFile(String fName) throws IOException {
            // TODO Auto-generated constructor stub
            try{
                File NewFile=new File(fName);
                FileWriter wt=new FileWriter(NewFile,true);
                BufferedWriter bw=new BufferedWriter(wt);
                bw.close();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
    }
    package File;
    
    public class GreadName {
        public static String Name=null;
        public GreadName(int length) {
            // TODO Auto-generated constructor stub
            char[] s = new char[length];
            for(int i=0;i<s.length;i++){
                int f=(int)(Math.random()*3);
                if(f==0)
                    s[i]= (char) (('A')+Math.random()*26);
                if(f==1)
                    s[i]= (char) (('a')+Math.random()*26);
                if(f==2)
                    s[i]= (char) (('0')+Math.random()*10);
            }
            Name=new String(s);
        }    
    }
  • 相关阅读:
    1150 Travelling Salesman Problem(25 分)
    poj 2408 Anagram Groups
    guava学习--ratelimiter
    guava学习--Objects
    guava学习--ComparisonChain
    guava学习--Preconditions
    guava学习--Function、Predicate
    guava学习--FutureFallback
    guava学习--FutureCallback
    guava学习--SettableFuture
  • 原文地址:https://www.cnblogs.com/leonxiaosi/p/2892824.html
Copyright © 2011-2022 走看看