java随机生成数字字母混合密码工具类


说明:只做记录,方便以后使用,只是不想重复造轮子

package uti.home;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class tt {

    public static void main(String[] args) throws IOException {
        
          File f = new File("C:\\Users\\HUAWEI\\Desktop\\data.txt");
          BufferedWriter bw= new BufferedWriter(new FileWriter("C:\\Users\\HUAWEI\\Desktop\\temp.txt"));
          BufferedReader br = new BufferedReader(new FileReader(f));
          String line =null;
          while((line=br.readLine())!=null) { 
              if(!line.contains("<-")) {
                  line = line.concat("\t->密码"+getpass(8)).concat("\n");
              }else {
                  line = line.concat("\n");
              }
              bw.write(line); 
         } 
          bw.flush();
          bw.close();
         
        
    }
    public static String getpass(int nums) {
        StringBuffer sb = new StringBuffer();
        for(int i=0;i) {
            int num = (int) (Math.random() * 10);
            int numchar = (int) (Math.random() * 26);
            
            sb.append(num).append((char)(numchar+65));
        }
        return sb.toString();
    }
}