不使用上下文保存和加载文件-Android 标题
我有一个android项目,并希望在此之后将其更改为一个清晰的体系结构。 我有三层、数据、域和表示。在我之前的结构中,我对将数据访问与Android特定组件链接不感兴趣,因此我使用上下文访问本地文件目录,如下所示不使用上下文保存和加载文件-Android 标题,android,local-storage,android-context,Android,Local Storage,Android Context,我有一个android项目,并希望在此之后将其更改为一个清晰的体系结构。 我有三层、数据、域和表示。在我之前的结构中,我对将数据访问与Android特定组件链接不感兴趣,因此我使用上下文访问本地文件目录,如下所示 File file = new File(act.getFilesDir(), filename); FileOutputStream outputStream; try { outputStream = act.openFileOutput(file
File file = new File(act.getFilesDir(), filename);
FileOutputStream outputStream;
try {
outputStream = act.openFileOutput(filename, act.MODE_PRIVATE);
outputStream.write(response.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Variable act引用活动,但现在我不想让数据层(在其中我可以访问文件)链接到Android特定的东西
有没有一种方法可以不使用活动就访问本地目录?不通过上下文直接访问本地目录确实是不可能的。如果要将数据层与Android组件完全解耦,一种方法是将
act.getFilesDir()
返回的文件对象作为参数传递给数据层