Solved

File Manipulations

Posted on 2001-06-14
7
228 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
ID: 6190442
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
ID: 6190473
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
ID: 6190507
so what's new ?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 9

Expert Comment

by:Ovi
ID: 6190519
so what's new ?
0
 
LVL 3

Expert Comment

by:chrisos
ID: 6191075
Eh?
0
 

Expert Comment

by:teacher_mod
ID: 6198415
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
ID: 8289470
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 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