sd카드에 파일 저장시 파일명이 중복되면 이름을 바꾸도록 했는데요 여러개일경우 어떤식으로 해야되는지 궁금합니다
public void onClick(View arg0) {
OutputStream outStream = null;
String extStorageDirectory = Environment
.getExternalStorageDirectory().getAbsolutePath();
String fpath = extStorageDirectory + "/DCIM/Camera";
File file = new File(fpath, "바보1.jpg");
File file2 = new File(fpath, "바보2.jpg");
if (file.exists()) {
Log.e("LSJ", "File Check:" + file.exists());
file.renameTo(file2);
}
try {
outStream = new FileOutputStream(file);
mSaveBm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Toast.makeText(MainActivity.this, "Saved", Toast.LENGTH_LONG)
.show();
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, e.toString(),
Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, e.toString(),
Toast.LENGTH_LONG).show();
}
}
};
.