SDカードの「playerdata.txt」というファイルを削除したいです。次のコードは機能しません
{
File file = new File("/sdcard/GameHacker/playerdata.txt");
file.delete();
}
私の問題は、「playerdata.txt」をGameHackerというフォルダーにコピーしたいことです。このコードを使用します
Context Context = getApplicationContext();
String DestinationFile = "/sdcard/GameHacker/playerdata.txt";
if (!new File(DestinationFile).exists()) {
try {
CopyFromAssetsToStorage(Context, "playerdata", DestinationFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void CopyFromAssetsToStorage(Context Context, String SourceFile, String DestinationFile) throws IOException {
InputStream IS = Context.getAssets().open(SourceFile);
OutputStream OS = new FileOutputStream(DestinationFile);
CopyStream(IS, OS);
OS.flush();
OS.close();
IS.close();
}
private void CopyStream(InputStream Input, OutputStream Output) throws IOException {
byte[] buffer = new byte[5120];
int length = Input.read(buffer);
while (length > 0) {
Output.write(buffer, 0, length);
length = Input.read(buffer);
}
}
それは正常に動作しますが、2回目は置き換えられません。最初にそれを削除してからコピーし、追加します
> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
明らかにする