當幸福來敲門

          我就會牢牢抓??!
          隨筆 - 50, 文章 - 3, 評論 - 8, 引用 - 0
          數據加載中……

          讀取 文本 文件內容 FileInputStream 亂碼處理

            StringBuffer content = new StringBuffer();
          //  FileInputStream fis = null;
          //  byte[] b = new byte[2048];
          //  try {
          //    if(lang!=null&&lang.trim().equals("10")){
          //     fis = new FileInputStream(passwordTemplatePath);
          //     }else if(lang!=null&&lang.trim().equals("20")){
          //      fis = new FileInputStream(passwordTemplateEnPath);
          //     }else if(lang!=null&&lang.trim().equals("30")){
          //      fis = new FileInputStream(passwordTemplateChinaEnPath);
          //     }
          //     int m = 0;
          //   while ((m = fis.read(b)) != -1) {
          //    content.append(new String(b, 0, m));
          //   }
          //passwordTemplatePath 文本 文件地址
            BufferedReader br = null;
            try {
              if(lang!=null&&lang.trim().equals("10")){
                   br =  new BufferedReader(new InputStreamReader(new FileInputStream(passwordTemplatePath), "utf-8"));
                }else if(lang!=null&&lang.trim().equals("20")){
                 br =  new BufferedReader(new InputStreamReader(new FileInputStream(passwordTemplateEnPath), "utf-8"));
               }else if(lang!=null&&lang.trim().equals("30")){
                  br =  new BufferedReader(new InputStreamReader(new FileInputStream(passwordTemplateChinaEnPath), "utf-8"));
                }
              String s = null;
              while ((s = br.readLine()) != null) {
              content.append(s);
             }
            } catch (Exception e) {
             e.printStackTrace();
            } finally {
             try {
              br.close();
             } catch (IOException e) {
              e.printStackTrace();
             }
            }

          posted on 2012-06-26 17:15 wyx 閱讀(2123) 評論(2)  編輯  收藏

          評論

          # re: 讀取 文本 文件內容 FileInputStream 亂碼處理  回復  更多評論   

          是西安市阿薩啊啊啊
          2014-10-21 20:29 | 實打實

          # re: 讀取 文本 文件內容 FileInputStream 亂碼處理[未登錄]  回復  更多評論   

          越來越好,直接報錯了。
          2016-06-05 11:54 | 小明

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 都兰县| 建阳市| 蓬安县| 湘西| 米易县| 吴忠市| 浦北县| 宜章县| 兴仁县| 哈巴河县| 新兴县| 广州市| 巴青县| 乌什县| 葵青区| 巨鹿县| 偏关县| 壶关县| 澎湖县| 贵德县| 保靖县| 太和县| 林口县| 鲜城| 新化县| 榆社县| 合作市| 永川市| 通州区| 富宁县| 龙游县| 积石山| 赣榆县| 六枝特区| 茂名市| 华蓥市| 深泽县| 东辽县| 榆树市| 濮阳市| 广饶县|