【发布时间】:2012-01-18 11:26:35
【问题描述】:
我需要知道 assets 文件夹中文件的 字符串路径,因为我使用的地图 API 需要接收字符串路径,并且我的地图必须存储在 assets 文件夹中
这是我正在尝试的代码:
MapView mapView = new MapView(this);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMapFile("file:///android_asset/m1.map");
setContentView(mapView);
"file:///android_asset/m1.map" 出了点问题,因为地图没有加载。
存储在我的资产文件夹中的文件 m1.map 的正确字符串路径文件是什么?
谢谢
为 Dimitru 编辑:此代码不起作用,它在 is.read(buffer); 上失败并出现 IOException
try {
InputStream is = getAssets().open("m1.map");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
text = new String(buffer);
} catch (IOException e) {throw new RuntimeException(e);}
【问题讨论】:
-
我找到了一种方法来参考我的答案here
标签: android assets android-assets