У меня есть проблема с структурой доступа к хранилищам, которые не правильными копиями файлов правильно. базовое имя файла, поэтому я получаю < /p>
hoot.db3(1) вместо ahoot (1) .db3. Файл правильно при сохранении, но я не знаю, как получить SAF, чтобы правильно копировать файл, чтобы расширение оставалось прежним. < /p>
File destination = new File(DEST_PATH + File.separator + DB_NAME);
int num = 0;
while (destination.exists()) {
num++;
String[] alt = DB_NAME.split("\\.(?=[^\\.]+$)"); // CHANGE
destination = new File(DEST_PATH + File.separator + alt[0] + "(" + num + ")" + "." + alt[1]);
}
< /code>
Использование URI < /p>
public void copyUriDatabase(InputStream in, Uri destinationUri) {
try {
OutputStream out = null;
out = this.getContentResolver().openOutputStream(destinationUri);
byte[] buffer = new byte[1024];
int read;
try {
while ((in.read(buffer)) > 0) {
if (out != null) {
out.write(buffer);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
if (out != null) {
out.flush();
out.close();
}
in.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
< /code>
URI происходит от
uri destinationUri = resultData.getData (); < /p>
Подробнее здесь: https://stackoverflow.com/questions/794 ... -of-copies