Java read large file simple instance _java

Source: Internet
Author: User

I want to extract useful data from a text file
Text file more than 200 MB
Is it possible to build a cache to put forward useful data for a paragraph, and what should I do?
---------------------------------------------------------------

Oh, 200MB just ...
In Java, you can use a memory-mapped file to manipulate large files.
Up to 2GB Max.
Here is a simple example of a more specific look at the Java API Docs or related information

Copy Code code as follows:

Import java.io.*;
Import java.nio.*;
Import java.nio.channels.*;
public class Largemappedfiles {
static int length = 0X8FFFFFF; 128 Mb
public static void Main (string[] args) throws Exception {
Mappedbytebuffer out =
New Randomaccessfile ("Test.dat", "RW"). Getchannel ()
. Map (FileChannel.MapMode.READ_WRITE, 0, length);
for (int i = 0; i < length; i++)
Out.put ((Byte) ' X ');
System.out.println ("finished writing");
for (int i = LENGTH/2 I < LENGTH/2 + 6; i++)
System.out.print ((char) out.get (i)); Read file
}
} ///

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.