jmeter经验----java 读取文件中文乱码问题
很少写java io的代码,今天整了一个发现 本地调试好好的,放到jmeter里就打印乱码。一番折腾,终于搞定~直接上代码:
List<Order> orderList = new ArrayList<Order>(); InputStream fis = null; InputStreamReader isr = null; BufferedReader br = null; try { String jsonStr = ""; //fis = new FileInputStream(fileName); fis = this.getClass().getResourceAsStream("/"+fileName); isr = new InputStreamReader(fis,"UTF-8");//此处需要指定编码,否则会用默认的,jmeter默认的是不支持中文的。 br = new BufferedReader(isr); while ((jsonStr = br.readLine()) != null) { Gson gson = new Gson(); //System.out.println("jsonStr---->"+jsonStr); Order order = gson.fromJson(jsonStr, Order.class); orderList.add(order); } } catch (Exception e) { e.printStackTrace(); } finally { br.close(); isr.close(); fis.close(); }
持续学习、持续收获才能带来持续的满足和快乐!