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);
        }    
    }
  • 相关阅读:
    预备作业03
    预备作业02
    预备作业01
    20162319莫礼钟 2016-2017-2 《程序设计与数据结构》第1周学习总结
    预备作业03
    20162319 莫礼钟 预备作业02
    20162319莫礼钟 预备作业01
    20162307 实验一 实验报告
    20162307 第4周学习总结
    20162307 第3周学习总结
  • 原文地址:https://www.cnblogs.com/leonxiaosi/p/2892824.html
Copyright © 2011-2022 走看看