It Prints nothing from the ArrayList?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 13
Reputation: jaka.ramdani is an unknown quantity at this point 
Solved Threads: 2
jaka.ramdani jaka.ramdani is offline Offline
Newbie Poster

Re: It Prints nothing from the ArrayList?

 
0
  #11
May 25th, 2009
Originally Posted by caps_lock View Post
oh my fault i didnt make all the changes it does compile, rep for you!
glad it helps .. thanks for the rep.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

Re: It Prints nothing from the ArrayList?

 
0
  #12
May 25th, 2009
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

  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

Re: It Prints nothing from the ArrayList?

 
0
  #13
May 25th, 2009
it does print now:



this is some sample output

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

confusing...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC