Is there a common way to access files, that works both on android and PC?
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 FileInputStream
s instead, because some files contain references to another ones, so I need a way to access 开发者_StackOverflow社区them from the method code.
Any suggestions?
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.
精彩评论