Java read large file simple instance

Source: Internet
Author: User

  This article mainly introduces Java reading large files simple examples, the need for friends can refer to the

I'm going to extract useful data   text files from a text file. 200 mb  is it possible to build a cache to put useful data in a section of the proposed, what should I do?     Java can use memory-mapped files to manipulate large files .  max 2gb.  Below is a simple example, more specific look at the Java API Docs or related data       code is 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 {       MAPPEDBYT Ebuffer out =          new randomaccessfile ("Test.dat", "RW"). Getchannel ()       &N Bsp  .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.PRI NT ((char) out.get (i));    //read file     } }///
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.