我的资源文件在哪里

问题描述:

我的android和存储选项(内部存储)有问题。我的资源文件在哪里

我在“原始”目录中添加了一个SSL证书,我想写入存储。

在那一刻,我有此代码段尝试它:

  InputStream is = SA.getResources().openRawResource(R.raw.myResource); 
      ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 

      int nRead; 
      byte[] data = new byte[16384]; 

      while ((nRead = is.read(data, 0, data.length)) != -1) 
      { 
      buffer.write(data, 0, nRead); 
      } 

      buffer.flush(); 

      FileOutputStream fos = SA.openFileOutput("Resource.crt", 0); 
      fos.write(buffer.toByteArray()); 
      fos.close(); 
      is.close(); 
      buffer.close(); 
      File f = new File(this.fileList()[0]); 
      if(f.exists()) 
      { 
       Log.v("File:", "Found"); 
      } 
      else 
      { 
       Log.v("File:", "Not found"); 
      } 

我的文件没有找到。我不知道为什么。

+0

后的fileList()方法的代码?问题代码位于Activity或Class的位置?需要更多信息。 – 2013-04-20 12:28:39

+0

这里这个文件列表:http://developer.android.com/reference/android/content/Context.html#fileList() – GoatMachine 2013-04-20 12:30:12

+0

尝试给你的证书文件一个完全小写的名字。如果它确实被称为'myResource',它可能不会被编译到您的应用程序中,因为只允许使用小写字母,数字,下划线和全部止点。 – 2013-04-20 13:01:06

我相信fileList刚刚返回的文件名,但你也需要的目录尝试:

File f = new File(context.getFilesDir(), filename); 
if(f.exists()){ 
    ... 

这里阅读:

http://developer.android.com/training/basics/data-storage/files.html#WriteInternalStorage

+0

啊,谢谢。 :) – GoatMachine 2013-04-20 13:44:33

+0

@MarcoSchmidt好,接受答案,如果它的工作。 – 2013-04-20 13:56:25