So im working on a project where im supposed to dynamically load the contents of a .csv file into the database.I have been hard coding the path of the file till now like
*
inserted = insertFromFile("C:/Users/Student/Desktop/Book1.csv",connection, "customer");
*
however now i have to read multiple files from a folder and integrate the program with a GUI. I have 2 questions:

a)how do i read multiple files from a folder b)how do i retrieve the path of a file for the insert statement

any help is appreciated.

Thanks!

Recommended Answers

All 2 Replies

The FIle class has methods that will return an array of the files contained in a folder.
The File class has methods for getting the path to a file.

public static void main(String[] args) {

       File[] files=new File("C:\\test\\").listFiles();

       for(File file:files) {

        System.out.println(file.getPath());

        readFile(file);

       }
    }

    private static void readFile(File file) {
        //method of reading file here
    }

Perhaps that will help, just give it a name of the directory with files and see the output

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.