JAVA IO - How To Bind A List With Desktop Files Name In Java

JAVA IO - How To Fill A List With Desktop Files Name In Java

__________________________________________________________________________

In this java IO Tutorial we will see How To Populate A List With Files Name
In Java NetBeans .



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:
How To Fill A List With Desktop Files In Java
Populate A List With Desktop Files In Java



Share this

Related Posts

Previous
Next Post »