62,616
社区成员
发帖
与我相关
我的任务
分享
public void Handle() {
try {
FileReader fs = new FileReader("adult.txt");
BufferedReader br = new BufferedReader(fs);
FileWriter fw = new FileWriter("out.txt");
BufferedWriter bw = new BufferedWriter(fw);
String strLine = null;
String[] temp;
strLine = br.readLine();
int m = 0;
boolean test=false;
String strTemp = null;
while (strLine != null) {
temp = strLine.split(","); //将文件adult.txt中的每一行以逗号分隔开, 返回字符串数组temp,
String[] temp1 = new String[8]; //用于取temp字符串数组中特定的字段..
temp1[0] =temp[0].substring(0, temp[0].length());
temp1[1] =temp[1].substring(0, temp[1].length());
temp1[2] =temp[3].substring(0, temp[3].length());
temp1[3] =temp[5].substring(0, temp[5].length());
temp1[4] =temp[6].substring(0, temp[6].length());
temp1[5] =temp[8].substring(0, temp[8].length());
temp1[6] =temp[9].substring(0, temp[9].length());
temp1[7] =temp[13].substring(0, temp[13].length());
for(int i=0;i<8;i++)
if(temp1[i].equals("?")) //判断所取字段中是否有"?"这样的字符串,原adult数据中有的行是有?号存在的,为什么这里检测不出来?
{
test=true;
break;
}
if(test!=true)
{
strTemp = temp1[0] + " " + temp1[1] + " " + temp1[2] + " "
+ temp1[3] + " " + temp1[4] + " " + temp1[5] + " "
+ temp1[6] + " " + temp1[7] + " " +"\n";
for (int i = 0; i < 8; i++) {
System.out.print(temp1[i] + " ");
}
System.out.println();
m++;
bw.write(strTemp);
strLine = br.readLine();
}
else
{
strLine = br.readLine();
continue;
}
}
System.out.println("i= " + m + " ");
bw.close();
fw.close();
br.close();
fs.close();
} catch (IOException io) {
}
}