leonxiaosi

创建随机的文件

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

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案