I could not understand how to debug the error i have now.
target
1- read the files from directory // i able ot do this part
2- for each file
for each file read the content & compare with the existing List & update the list // i able to do this part
when i try to combine both parts , i got some following error
i can see from the code that children[i] only gives the error when i use that in the second part of the code.
run:
E:\java\check\100130.ixf
Error: children[i] (The system cannot find the file specified)
BUILD SUCCESSFUL (total time: 2 seconds)
can any one help me on this??
Thanks
Priyan
the original code
Expand|Select|Wrap|Line Numbers
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStreamReader;
- import java.io.RandomAccessFile;
- import java.util.ArrayList;
- public class CompareList
- {
- public static void main(String[] args){
- ArrayList a1 = new ArrayList();
- ArrayList a2 = new ArrayList();
- a1.add("1");
- a1.add("2");
- a1.add("3");
- a1.add("4");
- a1.add("5");
- a1.add("6");
- a1.add("7");
- a1.add("8");
- a1.add("9");
- a1.add("10");
- a1.add("11");
- a1.add("12");
- a1.add("13");
- a1.add("14");
- a1.add("15");
- a1.add("16");
- a1.add("17");
- a1.add("18");
- a1.add("19");
- a1.add("20");
- a1.add("21");
- a1.add("22");
- a1.add("23");
- a1.add("24");
- a1.add("25");
- a1.add("26");
- a1.add("27");
- a1.add("28");
- a1.add("29");
- a1.add("30");
- a1.add("31");
- a1.add("32");
- a1.add("33");
- a1.add("34");
- a1.add("35");
- a1.add("36");
- a1.add("37");
- a1.add("38");
- a1.add("39");
- a1.add("40");
- a1.add("41");
- a1.add("42");
- a1.add("43");
- a1.add("44");
- a1.add("45");
- a1.add("46");
- a1.add("47");
- a1.add("48");
- a1.add("49");
- a1.add("50");
- a1.add("51");
- a1.add("52");
- try{
- File dir = new File("E:\\java\\check");
- File[] children = dir.listFiles();
- if (children == null) {
- System.out.println("does not exist or is not a directory");
- }
- else {
- for (int i = 0; i < children.length; i++) {
- System.out.println( children[i]);
- FileInputStream fstream = new FileInputStream("children[i]");
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String strLine;
- while ((strLine = br.readLine()) != null) {
- String line =strLine.substring(0,2);
- // Print the content on the console
- //System.out.println(line);
- a2.add(line);
- } // end of add list2
- if (a1.size() > a2.size())
- {
- int k = 0;
- for (int l = 0; l < a2.size(); l++)
- {
- if (!((String)a1.get(l)).equals((String)a2.get(l)))
- {
- //System.out.println((String)a2.get(i));
- // System.out.println("dd");
- }
- k = l;
- }
- k++;
- for (int l = k; l < a1.size(); l++)
- {
- System.out.println((String)a1.get(l));
- String str = "children[l]";
- File file = new File(str);
- RandomAccessFile rand = new RandomAccessFile(file,"rw");
- rand.seek(file.length()); //Seek to end of file
- rand.writeBytes((String)a1.get(i)); //Write end of file
- rand.writeBytes("., 0.");
- rand.writeBytes("\n");
- }
- }// end of comparing and updating the list2
- in.close();
- }
- }
- }
- catch (Exception e){//Catch exception if any
- System.err.println("Error: " + e.getMessage());
- }
- }
- }