Solved

File Manipulations

Posted on 2001-06-14
7
219 Views
Last Modified: 2010-03-31
Hi.

 I have a couple of related problems thats why am putting at one place

1: I want to make a file chooser that just choose the last folder in the tree structure
of the directories in which there are  files . ant not to allow the user to select the
files. that is just folder (directory) and not the files



2:

and now i have got the users folder path in which his/her java files are residing,  i want to know

>>> how to read all the files term by tem and do manipulation of any kind on each file.

what i have thought is to read the name and path of every file and put that all in
a vector but how to do it i dont know



kindly help me am in real trouble..................

 
     waiting for realy a kind reply.            
                                  nandini
0
Comment
Question by:nandini_kumar
7 Comments
 
LVL 9

Accepted Solution

by:
Ovi earned 100 total points
Comment Utility
1. In the JFileChooser class you can specify the mode (only directories, only files, both) and filters.
2. Once you have a Directory selected, the file choodser will return to you an java.io.File object. In this File object, if is a directory you can call the method listFiles(), which will return to you an array of File objects. The rest depends on you (what you will do with the files).
0
 
LVL 3

Expert Comment

by:chrisos
Comment Utility
Nandini,

1. Extend JFileChooser and call setFileFilter().  All you have to do is extend the javax.swing.filechooser.FileFilter abstract class to implement to just show File objects where isDirectory() returns true and listFiles does not return a 0 length array.

Then override aproveSelection so that folders you can accept have contents of the right type.

2. Call listFiles on the File returned and iterate through the File array that is returned, call getPath() which returns a string with the full path of the file.  Do an addElement to the Vector and thats that!

Regards,

Chrisos.
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
so what's new ?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:Ovi
Comment Utility
so what's new ?
0
 
LVL 3

Expert Comment

by:chrisos
Comment Utility
Eh?
0
 

Expert Comment

by:teacher_mod
Comment Utility
Hello nandini_kumar,

You have a number of old open questions with comments you have not responded to.  Would you please resolve those open questions before you ask the experts to provide you with additional free services.

teacher_mod
Community Support Moderator
Experts-Exchange
teacher_mod@experts-exchange.com
0
 

Expert Comment

by:SpideyMod
Comment Utility
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now