1

I have a text file to load from assets folder of an android app to "/sdcard/appname/" but i want the lines to be randomize and save while copied to sdcard, here is the code that i write to copy but i struck at the part of how to randomize

    data_path="/sdcard/<appname>/"
    AssetManager assetManager = getAssets();
            InputStream in = assetManager.open("file.txt");
            OutputStream out = new FileOutputStream(data_path + "file.txt");

            // Transfer bytes from in to out
            byte[] buf = new byte[1024];
            int len;
            //while ((lenf = gin.read(buff)) > 0) {
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            //gin.close();
            out.close();

How can i randomize the lines while copying (i'm not a java guy started working on it recently so this is kind of a noob question)

asrlytics
  • 11
  • 1

1 Answers1

0

If you read in data from your text file, you can store it into some kind of data structure, say an array, you can randomize the array before writing it back to the file.

This answer from this question has a sample of how to randomize your array.

Community
  • 1
  • 1
D Ta
  • 864
  • 6
  • 17