日期:2014-05-20 浏览次数:20677 次
//判断文件编码 CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance(); detector.add(new ParsingDetector(false)); detector.add(JChardetFacade.getInstance()); detector.add(ASCIIDetector.getInstance()); detector.add(UnicodeDetector.getInstance()); java.nio.charset.Charset charset = null; try { charset = detector.detectCodepage(sourseFile.toURL()); } catch (Exception ex) { ex.printStackTrace(); } if (charset != null) { chartsetName=charset.name(); } else { chartsetName="UTF-8"; } //读入文本文件 BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileName),chartsetName)); while (in.ready()) { str = in.readLine().trim(); if (str.trim().equals("")) { break; } HashMap map=new HashMap(); //解析 String sno = str.substring(0, 16).trim(); ..... //放入map backMap.put(sno, myObj); }
Obj objTmp=backMap.get(sno1);