Hanan Anderson
Hanan Anderson

Reputation: 1

Spring Batch itemReader()

Is there a way to read a .csv file from MS network drive with username & password? The examples that I have seen only reads the .csv file by using setResource(“/.csv”) method Of FlatFileItemReader. I’d like to use FlatFileItemReader but I need to read the .csv file from ms network drive with username and password.

Thanks.

Upvotes: 0

Views: 162

Answers (1)

Sushil Behera
Sushil Behera

Reputation: 901

Spring batch has nothing to do with it.

Please look at open source SMBJ library which would help reading a file and turn into a Spring Resource which you can use in setResource method.

Sample code be written like this.

    SMBClient client = new SMBClient();

    try (Connection connection = client.connect("111.111.111.111")) {
        AuthenticationContext ac = new AuthenticationContext("USERNAME", "PASSWORD".toCharArray(), "DOMAIN");
        Session session = connection.authenticate(ac);

        // Connect to Share
        try (DiskShare share = (DiskShare) session.connectShare("SHARENAME")) {
            System.out.println("File Exist : " + share.fileExists("file.csv));
        }
    }

Upvotes: 1

Related Questions