我只在Android 9.0生产中有一个奇怪的问题,该应用程序在生产中很长时间,这个问题始于Android 9.0
进程:com.ae.paris10,PID:18804 java.lang.ArrayIndexOutOfBoundsException:length = 984; regionStart = 0; regionLength = 1024 在java.util.Arrays.checkOffsetAndCount(Arrays.java:1719) 在libcore.io.IoBridge.write(IoBridge.java:487) 在java.io.FileOutputStream.write(FileOutputStream.java:186)
private void copyStyleWithNewTilesPath() throws IOException {
InputStream myinput = getContext()
.getAssets().open("styleParis.json");
String outfilename = "/data/data/" + Config.APPLICATION_ID + "/databases/styleParis.json";
OutputStream myoutput = new FileOutputStream(outfilename);
byte[] buffer = new byte[1024];
int length;
while ((length = myinput.read(buffer)) > 0) {
String str = new String(buffer, "UTF-8");
if (str.contains("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf")) {
buffer = str.replace("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf", "file://" + obbPath + "/{z}/{x}/{y}.pbf").getBytes("UTF-8");
}
myoutput.write(buffer, 0, length); <<--- EXCEPTION HERE <<-----------
}
//Close the streams
myoutput.flush();
myoutput.close();
myinput.close();
}
我真的不明白发生了什么,因为FileOutputStream是Java和Android框架。
有人有什么想法吗?
我认为这将解决您的问题:
if (str.contains("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf"))
myoutput.write(str.replace("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf", "file://" + obbPath + "/{z}/{x}/{y}.pbf").getBytes("UTF-8"));
else
myoutput.write(buffer, 0, length);
if (str.contains("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf"))
// write(byte[] b) :: Writes b.length bytes from the specified byte array to myoutput.
myoutput.write(str.replace("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf", "file://" + obbPath + "/{z}/{x}/{y}.pbf").getBytes("UTF-8"));
else
myoutput.write(buffer, 0, length);