0

I'm trying to access a shared file from my app, e.g //172.24.9.13/c/2012xp.mdb

By doing:

new File("//172.24.9.13/c/2012xp.mdb");

it doesn't work.

I found the jCIFS library, and creating

new SmbFile("//172.24.9.13/c/2012xp.mdb");

it works, but the problem is that I need a java.io.File.

I have also seen that there is no way to mount smb's on android devices without rooting them.

Is there a way to get a java.io.File instance of my shared file?

redbeam_
  • 337
  • 2
  • 13
Emaborsa
  • 2,360
  • 4
  • 28
  • 50

2 Answers2

0

I don't think you'll be able to read it as java.io.File because it's not one.

If you absolutely need a java.io.File you'll probably have to call smbFile.getInputStream() and copy to a local file, than you use that local file.

Considering it's a .mdb file you're probably wanting to read data from the DataBase, and it might be a huge file and you don't want to copy it over. On that situation, your only option is to setup a server, with an api that replies in JSON and your app will send GET requests to it.

Budius
  • 39,391
  • 16
  • 102
  • 144
0

try this code. i'm not sure about .mdb file format. but this works for PDF files.

first create a SmbFileInputStream using your smb file.

in = new SmbFileInputStream(sFile);

Then create a output file in the device storage (SD card)

outputfile = new File(dir, "todevice.pdf");

Then create a FileOutputStream (java IO)

out = new FileOutputStream(outputfile);

Then read input(SMB) and write it in to the output(IO)

while ((read = in.read(buffer)) > 0  ) 
{
    try {
           out.write(buffer, 0, read);
    } catch (IOException e) {
    }
}

Now u have a file on your sd card

rwe
  • 177
  • 1
  • 1
  • 11