linux 下读写文件乱码 解决

来源:互联网 发布:淘宝在哪里可以买彩票 编辑:程序博客网 时间:2024/05/21 10:52

 写文件 乱码解决 

 

 new   OutputStreamWriter(new   FileOutputStream(filename),"GB2312");  

 

 

读文件乱码解决

 

 public String readInput(String filePath, String fileName)
   throws IOException {
  StringBuffer buffer = new StringBuffer();
  try {
   FileInputStream fis = new FileInputStream(filePath + fileName);
   InputStreamReader isr = new InputStreamReader(fis, “GBK or utf-8”);
   Reader in = new BufferedReader(isr);
   int ch;
   while ((ch = in.read()) > -1) {
    buffer.append((char) ch);
   }
   in.close();
   return buffer.toString();
  } catch (IOException e) {
   e.printStackTrace();
   return null;
  }
 }

原创粉丝点击