Begin the reading of a file from a specific line

前端 未结 3 1233
小蘑菇
小蘑菇 2021-01-27 18:01

i have a file similaire to this : ...

The hotspot server JVM has specific code-path optimizations
# which yield an approximate 10% gain over the client versi         


        
3条回答
  •  盖世英雄少女心
    2021-01-27 18:37

    try this code.

    public static HashMap getEnvVariables(String scriptFile,
                String config) {
            HashMap vars = new HashMap();
            BufferedReader br = null;
            try {
                FileInputStream fstream = new FileInputStream(scriptFile);
                br = new BufferedReader(new InputStreamReader(fstream));
                String strLine = null;
                String stopvar = "HDK7564";
                String startvar = "HDK1001";
                String keyword = "export";
                do {
                    if (strLine != null && strLine.contains(startvar)) {
                        if (strLine.contains(stopvar)) {
                            return vars;
                        }
                        while (strLine != null && !strLine.contains(stopvar)) {
                            strLine = br.readLine();
                            if (strLine.startsWith(keyword)) {
                                strLine = strLine.substring(keyword.length())
                                        .trim();
                                String[] split = strLine.split("=");
                                String name = split[0];
                                String value = split[1];
                                System.out.println(name + "=" + value);
                                vars.put(name, value);
                            }
                        }
                    }
                } while ((strLine = br.readLine()) != null);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return vars;
        }
    

提交回复
热议问题