後でテストにも使用するタブレットで、Android アプリケーションによって作成された zip ファイルがあります。Android タブレットと PC で開くことができます。つまり、破損していません。この .zip ファイルを Android テスト プロジェクトの /res/raw フォルダーに追加しました。ここで、junit テストケースの 1 つのこのファイルを Android デバイスにコピーしたいと思います。そのために、次のコードを使用します。
boolean success = false;
File appDirectory = MainActivity.getContext().getExternalFilesDir(null);
File pictureSketch = new File(appDirectory, sketchName+".zip");
if (!appDirectory.exists()) {
assertTrue("App directory could not be created.",appDirectory.mkdirs());
}
InputStream in = activity.getResources().openRawResource(raw.pictest);
FileOutputStream out = new FileOutputStream(pictureSketch);
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
success = true;
}
return success;
正しいファイルを含む zip ファイルが作成されますが、開くとエラー メッセージが表示されます: 不正な zip ファイルです。転送後に zip ファイルを開くことができるようにするには、何を変更すればよいですか?