SD 카드에서 "playerdata.txt"라는 파일을 삭제하고 싶습니다. 다음 코드는안드로이드 폰의 sdcard에서 파일 삭제하기
를 작동하지{
File file = new File("/sdcard/GameHacker/playerdata.txt");
file.delete();
}
내 문제는 내가 GameHacker라는 폴더에 "playerdata.txt"를 복사 할 내가이 코드를
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);
}
}
를 사용하고 잘 작동하지만 두 번째 시간 그것을 대체하지 않습니다 내가 먼저 복사 한 다음 그것을 삭제하고 싶은 나는
를 명시하기 위해> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
를 추가
나는 파일 경로가 잘못되었다고 생각합니다. – sanbhat
이 파일을 시도해보십시오. file = new File (android.os.Environment.getExternalStorageDirectory(),/GameHacker/playerdata.txt "); if (file.exists()) { file.delete(); }'사용 권한이 있는지 확인하십시오 android.permission.WRITE_EXTERNAL_STORAGE' in 매니 페스트 – Raghunandan