views:

57

answers:

1

Hi, I'm writing an application that will ship in two versions: Android and PC version.

Is there a simple way to access files from the shared code?

Using java.io is simple, but I don't know how to access android resources or assets using it. And I can't write methods that operate on FileInputStreams instead, because some files contain references to another ones, so I need a way to access them from the method code.

Any suggestions?

+2  A: 

Using java.io is simple, but I don't know how to access android resources or assets using it.

PCs do not have "resources or assets". By virtue of wanting to use "android resources or assets", you are already committed to not treating Android and the PC the same way.

So, write yourself a Java interface that gives the rest of your code access to whatever data you want. Write two implementations of that interface, one that uses java.io for files on the PC, one that uses Resources for Android.

CommonsWare
"Using reasources or assets" is the only way to access project files from Android. I don't know how to place anything directly in the android fileseystem.
m01
This does not change my answer. In fact, it makes my answer even more important. The way you will access these files on Android bears no resemblance to the way you will access these files on a PC. Hence, use a Java interface to isolate the environment-specific logic.
CommonsWare