У меня есть проблема с структурой доступа к хранилищам, неправильно именующему дублировать дублирования. (1) Вместо ahoot (1) .db3. < /P>
Использование унаследованного доступа к файлу я могу правильно назвать файл, но я не знаю, как перехватить и получить доступ к имени, используя URI . < /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 ... duplicates