5

Androidの内部メモリからSDカードの既存のディレクトリにプログラムでファイルを移動しようとしています。
私は2つの方法を試しました。最初のものでは、File.renameToを使用しました。

String destName = externalDirPath + File.separatorChar + destFileName;
File originFile = new File(cacheDirPath + File.separatorChar + originalfileName);

originFile.renameTo(new File(destName));

もう1つは、Runtime.getRuntime()を使用しました。

Process p = Runtime.getRuntime().exec("/system/bin/sh -");
DataOutputStream os = new DataOutputStream(p.getOutputStream());

String command = "cp " + cacheDirPath + "/" + originalfileName+ " " + externalDirPath + "/" + destFileName+ "\n";

os.writeBytes(command);

それらの両方でそれは動作しません..

何か提案はありますか?

4

1 に答える 1

7

のAndroidAPIリファレンスによるとrenameTo

両方のパスが同じマウントポイントにあります。Androidでは、アプリケーションが内部ストレージとSDカード間でコピーしようとすると、この制限に達する可能性が高くなります。

おそらく、をに読み込んでFileからbyte[]、新しいに書き込む必要がありFileます。 この答えはそれをカバーしています。

于 2012-05-19T13:44:51.520 に答える