Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws Exception {
- new Server().run();
- writeNew();
- read2();
- }
- private static void writeNew() throws Exception {
- FileInputStream in = new FileInputStream("C:/.pkx_v5/main_file_cachee.dat");
- byte[] buffer = new byte[1024];
- ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("C:/.pkx_v5/new.tar.gz"));
- int len = 0;
- while (in.read(buffer) > 0) {
- ++len;
- }
- o.writeInt(len);
- in.close();
- in = new FileInputStream("C:/.pkx_v5/main_file_cachee.dat");
- while (in.read(buffer) > 0) {
- o.writeObject(buffer);
- }
- o.close();
- in.close();
- }
- private static void read2() throws Exception {
- FileInputStream in = new FileInputStream("C:/.pkx_v5/new.tar.gz");
- ObjectInputStream obj = new ObjectInputStream(in);
- int line = obj.readInt();
- List<byte[]> bytes = new ArrayList<byte[]>();
- for (int i = 0; i < line; i++) {
- bytes.add( (byte[]) obj.readObject());
- }
- obj.close();
- byte[] finalArray = new byte[bytes.size() * 1024];
- int lastFilled = 0;
- for (byte[] array : bytes) {
- for (int i = 0; i < array.length; i++) {
- finalArray[lastFilled] = array[i];
- lastFilled++;
- }
- }
- FileOutputStream f = new FileOutputStream("C:/.pkx_v5/main_file_cache.dat");
- f.write(finalArray);
- f.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement