Java restore picture

Now there is a program that can randomly split a picture file in jpg format into 3 files according to the bytes. The splitting process is recorded in the splitlog.txt file. The format of the splitlog.txt file is as follows, and its content is divided into two columns. The middle is separated by , the first column represents which file the next content comes from in order, and the second column represents how many bytes are taken consecutively (known to be no more than 255 bytes):

0   59
1  47
2  26
0  34
1  80
2  95
0  107
1  52
2  198
0  180
1  120
2  179
0  169
1  47
2  80
0  132
1  83
2  39
0  195
1  151
2  63
0  56
1  79
2  187
0  194
1  181
2  152
0  180
1  57
2  145
0  24
1  68
2  8
0  137
1  76
2  97
0  109
1  176
2  112
0  110
1  173
2  63
0  126
1  68
2  66
0  90
1  47
2  20
0  187
1  150
2  84
0  15
1  30
2  128
0  37
1  3
2  116
0  171
1  75
2  191
0  122
1  127
2  13
0  96
1  140
2  30
0  187
1  194
2  168
0  79
1  116
2  162
0  153
1  177
2  9
0  190
1  44
2  149
0  184
1  196
2  116
0  47
1  117
2  147
0  109
1  34
2  18
0  88
1  85
2  120
0  19
1  120
2  179
0  170
1  39
2  20
0  107
1  18
2  97
0  113
1  154
2  159
0  19
1  119
2  16
0  161
1  150
2  51
0  57
1  28
2  196
0  56
1  16
2  100
0  183
1  80
2  91
0  193
1  160
2  111
0  187
1  136
2  138
0  40
1  185
2  31
0  120
1  79
2  88
0  47
1  123
2  27
0  129
1  45
2  34
0  68
1  116
2  35
0  119
1  176
2  61
0  26
1  120
2  37
0  79
1  19
2  35
0  98
1  119
2  75
0  120
1  24
2  139
0  76
1  194
2  196
0  118
1  19
2  143
0  42
1  95
2  58
0  198
1  190
2  153
0  162
1  158
2  60
0  54
1  99
2  175
0  178
1  104
2  15
0  57
1  158
2  170
0  121
1  59
2  66
0  39
1  50
2  65
0  183
1  176
2  168
0  184
1  198
2  184
0  4
1  121
2  81
0  49

For example: As stated above, first take 20 bytes from file 1, then take 15 bytes from file 3, then take 8 bytes from file 1, then take 4 bytes from file 2, and so on .
Please complete the code to restore the picture, submit the code and the restored picture

import java.io.*;
import java.util.ArrayList;

public class ReviewImage {
    private static int P1 = 0;
    private static int P2 = 0;
    private static int P3 = 0;

    public static void main(String[] args) throws IOException {
        ArrayList list = new ArrayList();
        String line = null;
        File file = new File("splitlog.txt");
        FileReader fileReader = new FileReader(file);
        BufferedReader br = new BufferedReader(fileReader);
        while ((line = br.readLine()) != null) {
            list.add(line);
        }
        FileOutputStream fileOutputStream = new FileOutputStream("a.jpg", true);
        for (int i = 0; i < list.size(); i++) {
            String[] arr = list.get(i).toString().split("\t");
            byte[] bytes = new byte[Integer.parseInt(arr[1])];
            switch (arr[0]) {
                case "0":
                    FileInputStream p1 = new FileInputStream("p1");
                    p1.skip(P1);
                    p1.read(bytes);
                    P1 = P1 + bytes.length;
                    fileOutputStream.write(bytes);
                    break;
                case "1":
                    FileInputStream p2 = new FileInputStream("p2");
                    p2.skip(P2);
                    p2.read(bytes);
                    P2 = P2 + bytes.length;
                    fileOutputStream.write(bytes);
                    break;
                case "2":
                    FileInputStream p3 = new FileInputStream("p3");
                    p3.skip(P3);
                    p3.read(bytes);
                    P3 = bytes.length + P3;
                    fileOutputStream.write(bytes);
                    break;
            }
        }
    }
}

Guess you like

Origin blog.csdn.net/Yajyaj123/article/details/128837819