Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2009, 07:21 AM
Member
 
Join Date: Mar 2009
Location: London
Posts: 8
Rep Power: 0
svpriyan is on a distinguished road
Send a message via Skype™ to svpriyan
Default Read file from directory, update contents of the each file
hai,
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
Quote:

run:
E:\java\check\100130.ixf
Error: children[i] (The system cannot find the file specified)
BUILD SUCCESSFUL (total time: 2 seconds)
i can see from the code that children[i] only gives the error when i use that in the second part of the code.

can any one help me on this??
Thanks
Priyan


the original code
Code:
 

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());
		}
	}
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-11-2009, 07:53 AM
RamyaSivakanth's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Chennai
Posts: 589
Rep Power: 1
RamyaSivakanth is on a distinguished road
Default
Hi,
Seeing your code I can say u are very new to Java.

One small suggestion.
Why are u adding 1,2,3...like this ...U can put a loop know?


Don't put quotes around this childern[i].
FileInputStream fstream = new FileInputStream(children[i]);

In your code ,lot of comments are there.But as a beginner I don't want to.Go thru some good Java material before starting something.

-Regards
Ramya
__________________
Ramya
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-11-2009, 11:07 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Originally Posted by RamyaSivakanth View Post
Don't put quotes around this childern[i].
FileInputStream fstream = new FileInputStream(children[i]);
Java doc explain about this more clearly, what are the correct arguments you have to pass.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to read openproj(Projity) file i.e. ,POD file(Project Management file) mahendra.athneria New To Java 0 02-11-2009 10:53 AM
swapping the contents of the file and writing to another file Ms.Ranjan New To Java 9 07-10-2008 05:52 PM
[SOLVED] File chooser selecting file from directory...? prabhurangan AWT / Swing 12 06-18-2008 05:08 AM
Is there a way to read a file directory willemjav Java Applets 2 04-17-2008 05:54 PM
How to read a text file from a Java Archive File Java Tip Java Tips 0 02-08-2008 10:13 AM


All times are GMT +2. The time now is 03:26 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org