943,704 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 995
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
May 25th, 2009
0

Re: It Prints nothing from the ArrayList?

Click to Expand / Collapse  Quote originally posted by caps_lock ...
oh my fault i didnt make all the changes it does compile, rep for you!
glad it helps .. thanks for the rep.
Reputation Points: 9
Solved Threads: 3
Newbie Poster
jaka.ramdani is offline Offline
18 posts
since Sep 2008
May 25th, 2009
0

Re: It Prints nothing from the ArrayList?

would some one be kind enough to copy and paste and compile this code, I get no results to the terminal, my criteria should bring a few results

Java Syntax (Toggle Plain Text)
  1.  
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class MainFourA
  6. {
  7. public static void main(String[] args)
  8. {
  9. File[] filesOnComputer = File.listRoots();
  10.  
  11. ArrayList listOfFiles = new ArrayList();
  12. System.out.println (filesOnComputer.length);
  13. for(int index = 0; index < filesOnComputer.length; index++)
  14. {
  15. listOfFiles.add((File)filesOnComputer[index]);
  16. if(filesOnComputer[index].isDirectory())
  17. {
  18. System.out.println ("here we are-"+filesOnComputer[index].getPath());
  19. search((File)listOfFiles.get(index));
  20. }
  21. else
  22. System.out.println ("This is not the directory-"+filesOnComputer[index].getPath());
  23. }
  24. }
  25.  
  26. public static void search(File f)
  27. {
  28. try
  29. {
  30. ArrayList<File> arrayList = new ArrayList<File>();
  31. ArrayList<File> arrayListAgain = new ArrayList<File>();
  32.  
  33. File[] files= f.listFiles();
  34. for(int index = 0; index < files.length; index++)
  35.  
  36. if (files[index].isDirectory())
  37. {
  38. search(files[index]);
  39. }
  40.  
  41. else if (files[index].isFile())
  42. {
  43.  
  44. System.out.println ("here we are---" + files[index].getName());
  45.  
  46. arrayList.add(files[index]);
  47. arrayListAgain.add(files[index]);
  48.  
  49. if (arrayList.get(index).length() == arrayListAgain.get(index).length() &&
  50. arrayList.get(index).hashCode() != arrayListAgain.get(index).hashCode())
  51. {
  52.  
  53. System.out.println (arrayList.get(index).getName() + ", " + arrayList.get(index).length() + " bytes.");
  54.  
  55. }
  56. }
  57.  
  58.  
  59. System.out.println (f.getName());
  60. }
  61. catch (Exception e)
  62. {
  63. }
  64. }
  65. }

it compiles, if you comment out the big if statement, then lots of results come to the terminal window

I hope know one is getting annoyed by me!
Last edited by caps_lock; May 25th, 2009 at 11:32 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
caps_lock is offline Offline
43 posts
since Nov 2008
May 25th, 2009
0

Re: It Prints nothing from the ArrayList?

it does print now:



this is some sample output

$R3QSQ3M
here we are---$R49HV83.txt
$Recycle.Bin
here we are---autoexec.bat

confusing...
Reputation Points: 10
Solved Threads: 0
Light Poster
caps_lock is offline Offline
43 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Urgent Help!
Next Thread in Java Forum Timeline: Switch Case





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC