Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:19:15+00:00 2026-06-07T04:19:15+00:00

public class readBin { public static void main(String[] args) throws IOException{ long time1 =

  • 0
public class readBin {
public static void main(String[] args) throws IOException{
    long time1 = System.currentTimeMillis();


File targetfile = new File("d:\\d2012.bin");
    FileInputStream in = new FileInputStream(targetfile);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    byte[] buffer = new byte[2097152];
    int byteread = 0;
    String bufferString = "";

    ArrayList<HashMap> arr = new ArrayList<HashMap>();
    ArrayList arrstr = new ArrayList();
    HashMap hashmap = new HashMap();
    ArrayList<String> cttarr = new ArrayList<String>();
    String[] strarr = new String[2];
    ArrayList<String> valarr = new ArrayList<>();
    //It's all init above,below comes the file reading
    bufferString = br.readLine();
    while(bufferString != null){
        //if data readed this line from the file is not "*newrecord" or ""
        if(!bufferString.equals("*NEWRECORD")&&!bufferString.equals("")){
            //according to the need,make use of these data
            strarr = bufferString.split("=");
            switch (strarr[0].trim()) {
            case "UI":
                hashmap.put(strarr[0].trim(), strarr[1].trim());
                break;
            case "MH":
                hashmap.put(strarr[0].trim(), strarr[1].trim());
                break;
            case "AQ":
                String[] valuearr = strarr[1].split(" ");
                hashmap.put(strarr[0], valuearr);
                break;
            case "ENTRY":
                bufferString = bufferString.split("\\|")[0].toString();
                //if key named ENTRY has already existed,update the data
                if (hashmap.containsKey(strarr[0].trim())) {
                    ArrayList<String> templist = ((ArrayList<String>)hashmap.get(strarr[0].trim()));
                    templist.add(bufferString.split("=")[1].trim());
                    hashmap.put(strarr[0].trim(), templist);
                //or insert it 
                } else {
                    cttarr.add(bufferString);
                    hashmap.put(strarr[0].trim(),cttarr);
                }
                break;
            case "MS":
                hashmap.put(strarr[0].trim(), strarr[1].trim());
                break;
            case "MN":
                //as ENTRY do
                if (hashmap.containsKey(strarr[0].trim())) {
                    ArrayList<String> templist =     ((ArrayList<String>)hashmap.get(strarr[0].trim()));
                    templist.add(strarr[1].trim());
                    hashmap.put(strarr[0].trim(), templist);
                } else {
                    cttarr.add(strarr[1].trim());
                    hashmap.put(strarr[0].trim(),cttarr);
                }
                break;

            default:
                break;
            }
        } else if(hashmap.size() != 0) {
            //if it equals to *newrecord or "",init the hashmap again
            arr.add(hashmap);
            hashmap = new HashMap();
        }
        bufferString = br.readLine();
        if (bufferString == null) {
            arr.add(hashmap);
        }
    }
    ArrayList arrresult = arr;
    long time2 = System.currentTimeMillis();
    System.out.println(time2-time1);
    String ui = (String) arr.get(0).get("MH");
    ArrayList<String> entrys = (ArrayList<String>) arr.get(0).get("ENTRY");
    int len = arr.size();
    System.out.println(ui);
    System.out.println(len);
}

public String getbs(){
    return "";
}
}

I want to iterate the data from the file and add them to the hashmap,after updating the hashmap to the arrayList,init the hashmap again.but from the result ,it seems the data in the hashmap wont clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:19:17+00:00Added an answer on June 7, 2026 at 4:19 am

    OK,Now I know how important it is to learn English well.

    I got the point now,in collection ,it is always reference instead of entity,so I shouldn’t write code as this

    ArrayList<String> templist = ((ArrayList<String>)hashmap.get(strarr[0].trim()));

    when I turned it to ArrayList<String> templist = new ArrayList<String>((ArrayList<String>)hashmap.get(strarr[0].trim()));,it runs good.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Test { public static void main(String[] args) throws Exception { String s1
public class Main { public static void main(String[] args) throws InterruptedException { ClassA a
public class Divers { public static void main(String args[]){ String format = |%1$-10s|%2$-10s|%3$-20s|\n; System.out.format(format,
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class Employee { public static void main(String[] args) { int j=3; staples[] stemp
public class InterruptedInput { public static void main(String[] args) { InputThread th=new InputThread(); //worker
public class Demo { public static void main(String args[]) { double d = 12.345;
public class Main { public static void main (String args[]) { int nums[]= {2,
public class Test { public static void main(String[] args) { } } class Outer
public class WrapperTest { public static void main(String[] args) { Integer i = 100;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.