现在的位置: 首页问题解决>正文
JAVA读取UTF-8编码格式的文件乱码解决
2010年05月14日 问题解决 暂无评论 ⁄ 被围观 1,556 views+

public String ReadFile(String s_FileName) {
  String s_Result = "";
  BufferedReader buf;
  try {
   buf = new BufferedReader(new InputStreamReader(new FileInputStream(s_FileName), "UTF-8"));

   String line = null;
   int flag = 1;
   while ((line = buf.readLine()) != null) {

    if (flag == 1) {
     line = line.substring(1);// 去掉文件头
     flag++;
    }

    s_Result += line;    
   }
   buf.close();

  } catch (UnsupportedEncodingException e) {
   System.out.println(e.getMessage());
  } catch (FileNotFoundException e) {
   System.out.println(e.getMessage());
  } catch (IOException e) {
   System.out.println(e.getMessage());
  }
  return s_Result;
 }

给我留言

留言无头像?


×
腾讯微博