贴出我的代码求解决一下。。一点小问题
File file = new File(path);
try {
InputStreamReader read = new InputStreamReader(new FileInputStream(file));
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
String[] s3 = null;
while ((lineTXT = bufferedReader.readLine()) != null) {
System.out.println(lineTXT);
s3 = lineTXT.split(",");
}
for (int i = 0; i < s3.length; i++) {
int count = i + 1;
if (s3[i] != s2[i]) {
{
System.out.println("第" + count + "个位置的值不同,值为" + s3[i]);
}
}
}
read.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
读取了文件的内容放在s3数组里里面然我我定义了一个 String[] s2 = {"124453", "258", "98", "123"};放我比较的时候如果条件写成i < s2.length 就可以正常运行但只能比较出前四项,引文两个数组长度不一样s3数组里面的内容比s数组里面的内容要多,把条件改成i < s2.length,结果比较出前四项之后报错ArrayIndexOutOfBoundsException: length=4; index=4,请问在我代码的基础上要怎么修改才能解决这个问题呢?比较两个长度不相等的数组~~~~