【发布时间】:2014-06-09 13:41:38
【问题描述】:
我的 file.csv 包含
**narendra.koribilli@uni.com**
**stefan.hummel@uni.com**
**ibrsduser**
**michel.csaba@uni.com**
**wsdl**
**lalit.choudhary@uni.com**
**Remedy Application Service**
**vinay.k.kedlaya@uni.com**
我想将这些内容写入另一个 .csv 文件,例如:
**narendra.koribilli@uni.com**, **some random_value()**
**stefan.hummel@uni.com**, **some random_value()**
**ibrsduser**,**some random_value()**
**michel.csaba@uni.com**,**some random_value()**
**wsdl**,**some random_value()**
**lalit.choudhary@uni.com**,**some random_value()**
**Remedy Application Service**,**some random_value()**
**vinay.k.kedlaya@uni.com**,**some random_value()**
在上面几行中,一些 random_value() 是为第一个字符串生成随机字符串的方法(即 narendra.koribilli@uni.com)
这是我尝试过的,但它为所有不同的员工姓名打印相同的随机值
这是我迄今为止尝试过的
String KeyValue="";
private static void getString() 抛出 IOException
{
PrintStream out = new PrintStream("D:\\fileUpdate.csv");
BufferedReader br=new BufferedReader(new FileReader("D:\\file.csv"));
String str=null;
while((str=br.readLine())!=null)
{
String fetch=Generate_StringForUSer(str);
out1.println(str+","+fetch);
}
}
private static String Generate_StringForUSer(String str) {
int keylen=str.length();
while (KeyValue.length () != keylen)
{
int rPick = r.nextInt(4);
if (rPick == 0)
{
int spot = r.nextInt(25);
KeyValue += dCase.charAt(spot);
}
else if (rPick == 1)
{
int spot = r.nextInt (25);
KeyValue += uCase.charAt(spot);
}
else if (rPick == 2)
{
int spot = r.nextInt (7);
KeyValue += sChar.charAt(spot);
}
else if (rPick == 3)
{
int spot = r.nextInt (9);
KeyValue += intChar.charAt (spot);
}
}
System.out.println (KeyValue);
return KeyValue;
}
输出是这样的......
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
6Tui3ClnNqk#$8gCEAHxA3Er0U!V$5m
为所有用户生成相同的随机字符串..不同名称应该不同...请告诉我哪里错了..谢谢大家
【问题讨论】: