• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

access .txt files under the particlar parent directory

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i give parent directory name dymamically, particular java program should aceess its .txt extension files under its subdirectories ?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To get a listing of all files in the current directory see this thread, actually its short enough that I might as well post the code again.

Now, rather than printing out the filename, you can use the string function (stringname).endsWith(".txt") to see if it has the .txt extention. That will give you all .txt files in the current directory. To do sub directories, you will need to loop through and (recursively) check each subsequent directory for txt files as well as more directorys.
If you need help with recusrion, check out a google search here.
If you need more help, just post.
 
ashok ks
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my recursive of sub-directories does not work. If u have sample code just post it
 
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Poorly factored code but it should work. Note that you can also attach a file filter to the listFiles method call to return only *.txt and directories; this way was just as easy.

[ February 11, 2004: Message edited by: Jeff Langr ]
 
ashok ks
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeff Langr.
System.getProperties().getProperty("user.dir"); -> it starts from the current working directory.
If i want to give any directory path (like D:/hai/bye ), then how can i dynamically mention my directory path ?
 
Jeff Langr
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pass it in via the command line. Use the args parameter to main to extract it:

-j-
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic