Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-22-2007, 10:44 PM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
Help with File in java
I am trying to view files in a given directory on the computer inside a java program.
Basically, when given a string such as "C:\My Documents", how would i display the names of the files inside that directory?
Furthermore how would I tell if those files are directories themselves or other types of files?
Sorry I do not have any code to post but I am digging through the api docs to try and find the right classes to use and having no luck. I only need ideas for classes to use if anyone has any ideas.
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 12:16 AM
Member
 
Join Date: Jul 2007
Posts: 55
Seemster is on a distinguished road
Code:
File dir = new File("directoryName"); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory } else { for (int i=0; i<children.length; i++) { // Get filename of file or directory String filename = children[i]; } } // It is also possible to filter the list of returned files. // This example does not return any files that start with `.'. FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return !name.startsWith("."); } }; children = dir.list(filter); // The list of files can also be retrieved as File objects File[] files = dir.listFiles(); // This filter only returns directories FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } }; files = dir.listFiles(fileFilter);

Last edited by levent : 07-26-2007 at 07:51 PM. Reason: Code placed inside [code] tag for better readibility.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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 a text file from a Java Archive File Java Tip Java Tips 0 02-08-2008 10:13 AM
Converting text file(.txt) to JPG file(.jpg) in java javadeveloper Advanced Java 0 11-09-2007 05:22 PM
Help with File in java cachi New To Java 1 08-07-2007 08:58 AM
exe File Java cachi New To Java 1 08-01-2007 02:50 PM
exe file with Java Heather New To Java 2 07-03-2007 05:54 PM


All times are GMT +3. The time now is 01:09 PM.


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