我想在将 .txt 文件复制到新文件后在屏幕上显示它的一些内容。文本文件的内容自始至终不是完全相同的结构。
当我这样做时
if (m[11].equals("Channel") && m[12].equals("ID")){ System.out.println("Wavelenght ID = " + m[9]);
我得到一个错误数组超出范围。
测试步骤:调试* Fpga 配置 ECFG *:EED 3:通道 ID
如果找到此行,我希望它显示 Wavelenght ID = 3
String p = path.replace("\\", "\\\\");
File file = new File(p);
File[] files = file.listFiles();
BufferedReader inputStream = null;
PrintWriter outputStreamI = null;
PrintWriter outputStreamO = null;
try {
String l,c;
for (int i=0; i<files.length; i++){
inputStream = new BufferedReader(new FileReader(files[i].getAbsolutePath()));
outputStreamI = new PrintWriter(new FileWriter("S:\\WRED_IBP\\" + files[i].getName().replaceFirst("[.][^.]+$", "")+ "Ingress.txt"));
outputStreamO = new PrintWriter(new FileWriter("S:\\WRED_IBP\\" +files[i].getName().replaceFirst("[.][^.]+$", "")+ "Egress.txt"));
while ((l = inputStream.readLine())!= null) {
String[] m=l.split(" ");
for(int d=0; d<m.length; d++){
c=m[d];
if (c.equalsIgnoreCase("ied_wred") ){outputStreamI.println(l); if (outputStreamI.checkError()){System.err.println("Error in output stream");}} //|| c.equalsIgnoreCase("WARNING") || c.equals("ERROR")
else if (c.equalsIgnoreCase("eed_brc_ibp")){outputStreamO.println(l); if (outputStreamO.checkError()){System.err.println("Error in output stream");}} // || c.equalsIgnoreCase("WARNING") || c.equals("ERROR")
}
}
}
} catch(IOException e){
System.err.println("Caught IOException: " + e.getMessage());
}//wait(10);
finally {
if (inputStream != null) {
try{ inputStream.close();} catch (IOException e) {e.printStackTrace();}}
if (outputStreamI != null) {outputStreamI.close();}
if (outputStreamO != null) {outputStreamO.close();}
}
}