Loading a map using Properties class

前端 未结 2 1354
甜味超标
甜味超标 2020-11-30 15:55

I have a map with 75000 entries and each entry value will be of size 10kb on average.

I load this map into memory using Properties class . But due to the size of the

2条回答
  •  伪装坚强ぢ
    2020-11-30 16:19

    Don't use Properties, which is legacy

    1. Divide entries into multiple files

    2. Read each file in sequence, load and process using Preferences

    Example code:

    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();
            }
        }
    }
    

    Sample xml:

    
    
    
    
    
    
      
      
        
        
          
            
            
          
        
      
    
    
    
    

提交回复
热议问题