试图用Java

时间:2015-12-05 18:16:43

标签: shift-jis

我正在尝试阅读以实用方式下载和提取的日语内容CSV文件。

读取CSV的代码

  String splitBy = ",";
            BufferedReader br;// = new BufferedReader(new FileReader(pathOfExcel + "\\KEN_ALL.CSV   "));
            br = new BufferedReader(new InputStreamReader(new FileInputStream(pathOfExcel + "\\KEN_ALL1.CSV"),"SHIFT-JIS")); 
              String line = "";
              int cnt = 0;
              while((line = br.readLine()) != null){
                  //System.out.println("Count :: " + cnt++);
                  List<Object> excelList = new ArrayList<Object>();
                  if(line != null){
                   String[] splitCells = line.split(splitBy);
                   excelList.add(splitCells[0].replace("\"", ""));
                   excelList.add(splitCells[1].replace("\"", ""));
                   excelList.add(splitCells[2].replace("\"", ""));
                   excelList.add(splitCells[3].replace("\"", ""));
                   excelList.add(splitCells[4].replace("\"", ""));
                   excelList.add(splitCells[5].replace("\"", ""));
                   excelList.add(splitCells[6].replace("\"", ""));
                   excelList.add(splitCells[7].replace("\"", ""));
                   excelList.add(splitCells[8].replace("\"", ""));
                   returnList.add(excelList);
                 }
              }
              br.close(); 

我已尝试过UTF-8和SHIFT-JIS,如下面的代码所示。

br = new BufferedReader(new InputStreamReader(new FileInputStream(pathOfExcel + "\\KEN_ALL1.CSV"),"UTF-8"));

当我尝试使用UTF-8和SHIFT-JIS进行编码时," excelList.add(splitCells[3].replace("\"", ""));"将返回以下输出。但原始输出应该在哪里ホッカイドウ

UTF-8 - ¶¯¶²ÄÞ³

Shift-JIS - テ筱ッツカツイテ 楪ウ

1 个答案:

答案 0 :(得分:0)

文件KEN_ALL1.CSV是JAPAN POST Co.,Ltd。提供的文件,对吗? https://www.post.japanpost.jp/zipcode/dl/kogaki-zip.html

我可以与您的程序一起读取文件,所以我认为程序没有问题。

Result of your program on my Eclipse console

我认为您的文件可能有问题。您可以使用可显示文件字符编码的文本编辑器(例如Notepad ++)读取CSV文件吗?文件的内容是否已汇总显示,并且字符编码确实像Shift-JIS这样?

KEN_ALL1.CSV shown in Notepad++