JAVA IO - How To Fill A List With Desktop Files Name In Java
__________________________________________________________________________
Project Source Code:
package javadb_001;
import java.awt.Color;
import java.io.File;
import java.awt.List;
import javax.swing.*;
public class Project extends JFrame{
public Project(){
super("Bind A List With Your Descktop Files");
List list = new List();
String path = "C:\\Users\\samsng\\Desktop";
getFiles(path,list);
list.setBounds(40, 20, 500, 300);
add(list);
setLayout(null);
getContentPane().setBackground(Color.decode("#bdb76b"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(600,400);
setVisible(true);
}
//function to get all files in a specefic path
public static void getFiles(String path,List ls)
{
File file = new File(path);
String[] files = file.list();
for(String s : files)
ls.add(s);
}
public static void main(String[] args){
new Project();
}
}
///////////////END
/////OUTPUT:
Populate A List With Desktop Files In Java |
Download Projects Source Code