0

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!

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by DavidKroukamp
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.