Hi friends , i have a assignmentin my course Information Retrival and text mining.
I have to develop a search engine in java.
i am reading data from 31103 files and have to do some processing in each...
but i am stuck in a logical error, i.e in the loop when i reach at the index of 1022 it changes the index and shows the data of 1023.txt, and at 1023 it shows the data of 1024.txt, and before 1022 it works perfect.

Can any one please help me out with problem.

Thank you.

Recommended Answers

All 6 Replies

File file = new File("G://University//5th semester//IRT//Assignments//A1//k102118//Documents//");
        String[] str = file.list();
        String text;
        BufferedReader in;

        for(int i=1; i<= str.length ;i++) {
            try {

                if(i == 1022){
                    in = new BufferedReader(new FileReader("G://University//5th semester//IRT//Assignments//A1//k102118//Documents//"+str[0]));
                    System.out.println(str[0]);
                }else if(i>1022){
                    in = new BufferedReader(new FileReader("G://University//5th semester//IRT//Assignments//A1//k102118//Documents//"+str[i-1]));                   
                    System.out.println(str[i-1]);
                }else{
                    in = new BufferedReader(new FileReader("G://University//5th semester//IRT//Assignments//A1//k102118//Documents//"+str[i]));
                    System.out.println(str[i]);
                }
                try {
                    text=in.readLine();
                    StringTokenizer tokenizer = new StringTokenizer(text," ");
                    System.out.println(tokenizer.countTokens());

                } catch (IOException e) {
                    //System.out.println("Error :");
                    e.printStackTrace();
                }
            } catch (ArrayIndexOutOfBoundsException  e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

Try debugging the code by printing out the values of the variables being used in the code.
What is: str[0], str[i-1] and str[i]

Why is this test in the code:

 if(i == 1022){

Dear Norm1,
I deduged and printed the values and found this issue.

well,
if(i == 1022).. these conditions were made to get proper data of my files.

Have you solved the problem? If not, plesase post the print outs that show the problem.

ya i have solved it somewhat Norm1, but i need logic of why this is happing ???

Please explain what is happening. Post the print outs that show the problem you are having and add some comments to the print out explaining what you don't understand.

If you have changed the code, you also need to post the new code with the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.