我的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");
}
我的文件沒有找到。我不知道爲什麼。
後的fileList()方法的代碼?問題代碼位於Activity或Class的位置?需要更多信息。 – 2013-04-20 12:28:39
這裏這個文件列表:http://developer.android.com/reference/android/content/Context.html#fileList() – GoatMachine 2013-04-20 12:30:12
嘗試給你的證書文件一個完全小寫的名字。如果它確實被稱爲'myResource',它可能不會被編譯到您的應用程序中,因爲只允許使用小寫字母,數字,下劃線和全部止點。 – 2013-04-20 13:01:06