我想打開一個位於我的android studio項目@ res/drawable/conan_obrian.png中的文件。但是,拋出了java.io.FileNotFoundException。我嘗試過不同的路徑名組合,但沒有結果。Android在運行時查找資源文件的位置?
這個片段被拋出異常:如果你有一個assets/drawable
文件夾
InputStream is;
byte[] buffer = new byte[0];
try {
final AssetManager assetMgr = context.getResources().getAssets();
is = assetMgr.open("drawable/conan_obrian.png");
buffer = new byte[is.available()];
is.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
serverAPI.register(userName, Base64.encodeToString(buffer,Base64.DEFAULT).trim(), myCrypto.getPublicKeyString());
您的資產文件夾實際上是否包含可繪製的文件夾? –
AS> 2.0中是否有默認資產文件夾? - 找不到它。 – XYseven
不是我所知道的。不過,您可以使用File> New菜單創建一個Assets文件夾。否則,我認爲我的答案是你正在尋找的。目前還不清楚爲什麼你需要一個字節數組 –