Hi so I’m working on an app and at the moment I have code that downloads a bunch of zip files to /sdcard/RAND I have it get all the files into a string array and now i want to move one of those zips randomly to /sdcard/RAND/use my app then will always go to that folder and use that zip when the app is opened. It’s to keep the app interesting since each of the zips do something differently. Thanks for any help on how I can then move it randomly.
package com.android.rand;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<String> w = new ArrayList<String>();
String[] a;
File f = new File("/mnt/sdcard/RAND");
for (File s : f.listFiles()) {
w.add(f.toString());
}
a = new String[w.size()];
a = w.toArray(a);
}
}
Since you have the file names in a string array, why not generate a random number between 0 and length-1, use that as the index into the array, grab that file name and move it. Would that work?
For example