を私はこれを行うファイル:
try{
InputStream inputStream = getResources().openRawResource(R.raw.some_file);
File tempFile = File.createTempFile("pre", "suf");
copyFile(inputStream, new FileOutputStream(tempFile));
// Now some_file is tempFile .. do what you like
} catch (IOException e) {
throw new RuntimeException("Can't create temp file ", e);
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
FilenameUtilsはどのパッケージですか? – MBU
Apache Commons-IO – mhaller
アプレットまたはアプリケーションでコードスニペットが機能しないことに注意してください。 JWSを使用して配備されました。リソースが編集を必要としない限り(イメージはありそうにない)、それを一時ファイルに展開するのは通常の方法ではありません。 –