java读取txt文KSdkjVGLzK本中如含有中文,可能会出现乱码,解决方案是: 1.要统一编码,java工程的编码,txt文本编码,java工程中的java文本编码都统一为utf-8; 2.利用 InputStrehttp://www.devze.comamReader(new FileInputStream(fileUrl), "utf-8")将文本再次设置为utf-8 3.具体代码如下 复制代码 代码如下: InputStreamReader isr; try { isr = new InputStreamReader(new FileInputStream开发者_Python(fileUrl), http://www.devze.com"utf-8"); BufferedReader read = new Bu编程客栈fferedReader(isr); String s=null; List<String> list = new ArrayList<String>(); while((s=read.readLine())!=null) { //System.out.println(s); if(s.trim().length()>1){ list.add(s.trim()); } } System.out.println("OK!"); } catch (UnsupportedEnchttp://www.devze.comodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
精彩评论