java 按行直接解析gz包

   public List<Bandwidth> praseFile2Bandwidth(File file) {
        List<Bandwidth> resultList = new ArrayList<Bandwidth>();
        BufferedReader br = null;
        try {
            if (file.getName().endsWith(".gz")) {
                br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
            } else {
                br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            }

            String s1 = null;
            while ((s1 = br.readLine()) != null) {
                System.out.println(s1);
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
        return resultList;

    }

你可能感兴趣的:(java)