Splitting a text file without reading it

Is there any method so that I can split a text file in java without reading it?

I want to process a large text file in GB, so I want to split the file into small parts and apply a stream for each file and combine the result for it.

Since I will read it for small parts, then splitting the file by reading it will not make any sense, since I will have to read the same file twice, and this will degrade my performance.

+5
source share
6 answers

Your threading attempt is poorly formed. If you need to perform significant data processing on your file, consider the following stream structure:

1 Reader Thread ( )

1..n Worker Threads (n , )

1 Writer Thread ( )

, Reader/Writer , IO .

, .

+2

. .

+2

, :

  • ""?
  • , , ( 1 ). , .

? , . , :

public static void loadFileFromInputStream(InputStream in) throws IOException {
  BufferedReader inputStream = new BufferedReader(new InputStreamReader(in));

  String record = inputStream.readLine();
  while (record != null) {
    // do something with the record
    // ...
    record = inputStream.readLine();
  }
}

... . . , . , IO .

! - , . !

+2

- , . . , , . , . , 8 16 .

+2

- , ( , , , , ).

Linux-, , csplit. , Java csplit yourbigfile.txt.

+1

. , .

, , , - - "" . , . RandomAccessFile , seek .

(, FileInputStream, , Java API , skip OS .)

:

  • , , , , . , "".

  • (, UTF-8), , .

+1

All Articles