版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36347817/article/details/81295387
放置Android工程下的assets文件夹,在assets
文件夹里面创建了一个styleMap
子文件夹。将里面的文件写到sd卡中。
写出文件代码:
try {
// 先获取系统默认的文档存放根目录
File parent_path = Environment.getExternalStorageDirectory();
File dir = new File(parent_path.getAbsoluteFile(), "data");
if(!dir.exists()){
dir.mkdir();
}
File file = new File(dir.getAbsoluteFile(), "style.data");
if(file.exists()){
return;
}
//读取数据文件
InputStream open = this.getResources().getAssets().open("styleMap/style.data");
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
int len;
byte[] buf = new byte[1024];
while((len=open.read(buf))!=-1){
fos.write(buf,0,len);
}
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
在高德地图中指定你写出文件的路径。
String path=Environment.getExternalStoragePublicDirectory("data").getPath()+"/style.data"
//该方法在AMap类中提供
setCustomMapStylePath(path);