package com.greensnow25;

import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.util.RandomAccess;

/**
 * public class  .
 *
 * @author grensnow25.
 * @version 1.
 * @since 15.02.17.
 */
public class SortLargeFile {





}

@@ -38,62 +38,9 @@
 .io.
-FileNotFoundException;%0Aimport java.io.RandomAccessFile
+*
 ;%0Aim
@@ -67,16 +67,42 @@
 mAccess;
+%0Aimport java.util.Scanner;
 %0A%0A/**%0A *
@@ -216,11 +216,2847 @@
 e %7B%0A
-%0A%0A%0A%0A%0A%7D
+    public static void main(String%5B%5D args) throws IOException %7B%0A%0A        SortLargeFile sort = new SortLargeFile(%22%5C%5Cchapter3%5C%5CInput_Output%5C%5Csrc%5C%5Cmain%5C%5Cjava%5C%5Ccom%5C%5Cgreensnow25%22);%0A        sort.sortFile();%0A        sort.split();%0A        sort.merge();%0A%0A    %7D%0A%0A    public SortLargeFile(String path) throws FileNotFoundException %7B%0A        this.path = path;%0A    %7D%0A%0A    private final String userDir = System.getProperty(%22user.dir%22);%0A    private String path;%0A    private RandomAccessFile fileSourse;%0A    String separator = System.getProperty(%22line.separator%22);%0A    private RandomAccessFile tempOne;%0A    private RandomAccessFile tempTwo;%0A    String one1;%0A    String two2;%0A%0A%0A    public void sortFile() throws IOException %7B%0A%0A    %7D%0A%0A    String line;%0A    String tempLine;%0A%0A    public void split() throws IOException %7B%0A%0A%0A        boolean firstLine = false;%0A        int count = 2;%0A        try (RandomAccessFile fileSourse = new RandomAccessFile(userDir + path + %22%5C%5Ctest.txt%22, %22rw%22);%0A             RandomAccessFile tempOne = new RandomAccessFile(userDir + path + %22%5C%5CtempOne.txt%22, %22rw%22);%0A             RandomAccessFile tempTwo = new RandomAccessFile(userDir + path + %22%5C%5Ctemptwo.txt%22, %22rw%22);) %7B%0A%0A%0A            while ((line = fileSourse.readLine()) != null) %7B%0A                if (!firstLine) %7B%0A                    firstLine = true;%0A                %7D else if (tempLine.length() %3E= line.length() && tempLine != null) %7B%0A                    count++;%0A                %7D%0A                if (count %25 2 == 0) %7B%0A                    tempOne.writeBytes(line);%0A                    tempOne.writeBytes(separator);%0A%0A%0A                %7D else if (count %25 2 != 0) %7B%0A                    tempTwo.writeBytes(line);%0A                    tempTwo.writeBytes(separator);%0A                %7D%0A                tempLine = line;%0A            %7D%0A%0A        %7D%0A%0A%0A    %7D%0A%0A    public void merge() throws IOException %7B%0A        try (RandomAccessFile fileSourseOne = new RandomAccessFile(userDir + path + %22%5C%5CtestOne.txt%22, %22rw%22);%0A             RandomAccessFile tempOne = new RandomAccessFile(userDir + path + %22%5C%5CtempOne.txt%22, %22rw%22);%0A             RandomAccessFile tempTwo = new RandomAccessFile(userDir + path + %22%5C%5Ctemptwo.txt%22, %22rw%22);) %7B%0A%0A            String one;%0A            String two = tempTwo.readLine();%0A%0A%0A            RandomAccessFile big = tempOne.length()-1 %3E tempTwo.length()-1 ? tempOne : tempTwo;%0A%0A%0A            while ((one = big.readLine()) != null) %7B%0A                tempOne.seek(0);%0A                if (one.length() %3C two.length()) %7B%0A                    fileSourseOne.writeBytes(one);%0A                    fileSourseOne.writeBytes(separator);%0A%0A%0A                %7D else if (two.length() %3C one.length()) %7B%0A                    fileSourseOne.writeBytes(two);%0A                    fileSourseOne.writeBytes(separator);%0A                    two = tempTwo.readLine();%0A                %7D%0A            %7D%0A%0A        %7D%0A    %7D%0A%0A%7D%0A
 %0A

Update date 25.02.17