0

I use the jmatIO library to read a .mat file. In plain java I can set the path to the matFileReader like this

MatFileReader mfr = new MatFileReader("/theta-phi_small_param5.mat");

and I can have access to all the .mat data. Inside the android i put the .mat file to the assets folder and I tried to access it like this

mfr = new MatFileReader("file:///assets/theta-phi.mat");

but it doesn't work. How can I get the path to the mat file inside the assets folder so to read it with the MatFileReader?

Alex Fragotsis
  • 1,248
  • 18
  • 36

1 Answers1

2

Does the MatFileReader accept an InputStream? If so you can do it like this:

InputStream in = getAssets().open("theta-phi.mat");

It might also work to use:

File file = new File("file:///android_asset/theta-phi.mat");

UPDATE: Since MatFileReader doesn't support InputStream and the File solution above doesn't work I guess your best bet is to copy the file from the Assets folder to your apps External/Internal storage and from there access the file.

Community
  • 1
  • 1
britzl
  • 10,132
  • 7
  • 41
  • 38
  • No it doesn't accept inputstream but I tried with to read the file and although I didn't have compile time error it gave me a run time error "NullPointerException" in the line where I try to read the file – Alex Fragotsis May 31 '13 at 11:20
  • Also the matFileReader throws FileNotFoundException (No Such file or directory) :/ – Alex Fragotsis May 31 '13 at 11:34
  • Well, your updated answer worked,I used a InputStream/OutputStream I wrote the file to the sd card and then I read it with " File f = new File("/sdcard/theta-phi.mat"); " and it worked fine! Thank you for your answer. The only problem that I faced is that i hadn't set an sd card for the emulator and I got some errors :P – Alex Fragotsis Jun 02 '13 at 17:00
  • Ah, excellent. I'm happy you got it working. Did you really have to set up an SD card though? I'm guessing that it would have been enough to check for the presence of external storage using Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) and if it's present you read/write the file to context.getExternalCacheDir().getAbsolutePath() and if not you read/write from context.getCacheDir().getAbsolutePath() – britzl Jun 03 '13 at 05:45