AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-swing: Access Directory Automatically

I want to make a UI project, which can access all the directories and provide the facility to choose a particular directory and arrange all files in folder w.r.t the file extenssion or file type such as mp3,mp4, and PDF etc.

corejava x 333
swing x 4
Posted On : 2017-07-20 15:49:09.0
profile Anonymous User - anyforum.in Anonymous User
1300
up-rate
5
down-rate

Answers


I think you must give option to select the drives for which user wants to filter the files. Please refer below code to get the system drives and add one check box for each on frame:

File[] drives=File.listRoots();
JFrame frame=new JFrame("File Filter");
frame.setSize(500, 500);
frame.setLocation(500, 500);
JCheckBox checkBox;
for(File file:drives){
if(file.canRead()){
checkBox=new JCheckBox(FileSystemView.getFileSystemView().getSystemDisplayName(file));
frame.add(checkBox);
}
}
frame.setVisible(true);


To get all the information about files or sub folders inside a directory please check below link as reference:

How to get all files and sub directories in java- Click Here

or to know the extension of file, it´s as simple as above code will return fileName with extension.

if(fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0)
return fileName.substring(fileName.lastIndexOf(".")+1);
else
return "";


Now all you need to do is now, integrate all the code snippet.

Posted On : 2017-07-21 23:58:31
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185418912
Reply This Thread
up-rate
0
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in