Loading a map using the property class

I have a card with 75,000 records, and each record value will average 10 KB.

I load this map into memory using the Properties class. But because of the size of the card, I get an OutOfMemoryException when there is not enough RAM on the host.

One option that I have is to read the entries in batches (e.g. 10,000) into memory instead of loading the full map. Read the next 10k after processing the initial 10k.

Is there a way to accomplish this using the Properties class.

Also, is there a better way to load map entries this way?

Thanks and Regards,
Sujit

+1
source share
2

Properties,

:

package com.mypack.test;

import java.io.*;
import java.util.*;
import java.util.prefs.Preferences;

public class PreferencesExample {

    public static void main(String args[]) throws FileNotFoundException {
        Preferences ps = Preferences.userNodeForPackage(PreferencesExample.class);
        // Load file object
        File fileObj = new File("d:\\data.xml");
        try {
            FileInputStream fis = new FileInputStream(fileObj);
            ps.importPreferences(fis);
            System.out.println("Prefereces:"+ps);
            System.out.println("Get property1:"+ps.getInt("property1",10));

        } catch (Exception err) {
            err.printStackTrace();
        }
    }
}

xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>
<preferences EXTERNAL_XML_VERSION="1.0">
<root type="user">
<map />
<node name="com">
  <map />
  <node name="mypack">
    <map />
    <node name="test">
      <map>
        <entry key="property1" value="80" />
        <entry key="property2" value="Red" />
      </map>
    </node>
  </node>
</node>
</root>
</preferences>
+2

, , . . lib , .

+1

Source: https://habr.com/ru/post/1619241/


All Articles