Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不使用上下文保存和加载文件-Android 标题_Android_Local Storage_Android Context - Fatal编程技术网

不使用上下文保存和加载文件-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

我有一个android项目,并希望在此之后将其更改为一个清晰的体系结构。 我有三层、数据、域和表示。在我之前的结构中,我对将数据访问与Android特定组件链接不感兴趣,因此我使用上下文访问本地文件目录,如下所示

   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()
返回的文件对象作为参数传递给数据层