나는 내가 시작하는 동안 SD 카드의/mnt/sdcard/Android/data/path에 복사해야 할 파일과 디렉토리가 거의없는 폴더가 있습니다. 처음에는 응용 프로그램, 물론 아직 필요한 폴더가없는 경우 해당 경로에 존재하지 않습니다.res/raw 폴더에서 sd 카드로 디렉토리 및 파일 복사 - android
이 폴더는 내 응용 프로그램의 res/raw 폴더 안에 있습니다.
폴더와 모든 내용을 res/raw에서 SD 카드의 지정된 경로로 복사 할 수있는 단계별 절차는 무엇입니까?
도움을 주시면 감사하겠습니다. 난 당신이 자산에 파일을 보관 제안
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
copyFileOrDir("edu1");//directory name in assets
}
File sdCard = Environment.getExternalStorageDirectory();
private void copyFileOrDir(String path) {
AssetManager assetManager = this.getAssets();
String assets[] = null;
try {
assets = assetManager.list(path);
if (assets.length == 0) {
copyFile(path);
} else {
File dir = new File (sdCard.getAbsolutePath() + "/" + "Android/data");
//String fullPath = "/data/data/" + this.getPackageName() + "/" + path;//path for storing internally to data/data
//File dir = new File(fullPath);
if (!dir.exists()){
System.out.println("Created directory"+sdCard.getAbsolutePath() + "/Android/data");
boolean result = dir.mkdir();
System.out.println("Result of directory creation"+result);
}
for (int i = 0; i < assets.length; ++i) {
copyFileOrDir(path + "/" + assets[i]);
}
}
} catch (IOException ex) {
System.out.println("Exception in copyFileOrDir"+ex);
}
}
private void copyFile(String filename) {
AssetManager assetManager = this.getAssets();
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
//String newFileName = "/data/data/" + this.getPackageName() + "/" + filename;//path for storing internally to data/data
String newFileName = sdCard.getAbsolutePath() + "/Android/data/" + filename;
out = new FileOutputStream(newFileName);
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
System.out.println("Exception in copyFile"+e);
}
}
}
지금까지 해본 코드에 일부 코드를 게시 하시겠습니까? 당신이 말하는 것처럼 보입니다. "내가하고 싶은 일이 여기에있다. –
아니, 제 질문을 편집 중입니다. – user1400538