My Java application requires access to a large excel file (1GB+ in size) saved on remote shared folder. I'm using SmbFile to get the file with authentication.
Note: Downloading of the file is not an option mainly for size reasons.
The problem is that I need the excel file to be a Java IO File and not SmbFile since the other libraries that I'm using to parse the excel only accepts Java IO File.
- Is there any way to convert this SmbFile into a Java compatible File?
Output
javadoc of smbFile.getUncPath() says
I am using jcifs-1.3.17.jar on Windows 10.
See implementation details of your library:
So it doesn't matter if you use the
File
orInputStream
API - the whole file will need to be downloaded anyhow.The simplest solution is to pass the
SmbFile.getInputStream()
tobut alternatively you can first download the file eg. by means of
IOUtils.copy()
orFiles.copy()
or
and pass
file
toIt's just a matter of structure I guess, with SmbFile we have two arguments while with File we have just one argument. So, my Idea is to declare a File with the same path of the SmbFile and try to handle your file. For example, in my I want to delete recursively the content of my folder :
}
I hope this peace of code help you, and sorry for my english !
Recently i had a similar situation, however, I hadn't found a good solution in the internet, but I wrote a basic code that did what I need easily.
In your case, you will need to copy the excel file from the source (Remote Directory) using SmbFile with authentication to the destination (Local Directory) and only after, convert the excel file path of the destination (getCanonicalPath() function) and convert it from SmbFile format to File format with the code below. After, create your File object with the file destination path and do what you want.
I use JCIFS to work with remote shared directories using the SMBFILE class.
First, you need to import the main libraries:
Second, you need to create a static method to convert from SmbFile format to File format:
Opcional, you could also create a static method to convert from File format to SmbFile format:
Finally, you can call the methods like the below example:
Result of previous code run:
Extra Information: getCanonicalPath()
Maybe this code will help you and I am available to talk about if you want.
Good Luck!