2 Replies Latest reply: Jan 26, 2013 7:11 AM by Dimitar Dimitrov RSS

    Read and write a .CSV file contains cirillic characters issue

    samme4life
      Hi guys,
      I am a developer of a web application project which uses Oracle Fusion Middleware technologies. We use JDeveloper 11.1.1.4.0 as development IDE.
      I have a requirement to get a .csv file from WLS to application running machine. I used a downloadActinLinsener in front end .jspx in order to do that.
      I use OpenCSV library to read and write .csv files.
      Here is my code for read and write the .csv file,
      -----------------------------------------------
      public void dwdFile(FacesContext facesContext, OutputStream out) {


      System.out.println("started");
      String [] nextLine;

      try {
      FileInputStream fstream1 = new FileInputStream("Downloads/filetoberead.CSV");
      DataInputStream in = new DataInputStream(fstream1);
      BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8"));
      CSVReader reader = new CSVReader(br,'\n');
      //CSVReader reader = new CSVReader(new FileReader("Downloads/ACTIVITY_LOG_22-JAN-13.csv"),'\n');
      List<String> list=new ArrayList();
      while ((nextLine = reader.readNext()) != null) {

      if(nextLine !=null){
      for(String s:nextLine){
      list.add(s);
      }
      }
      }
      System.out.println("list size ; "+list.size());
      OutputStreamWriter w = new OutputStreamWriter(out, "UTF-8");
      CSVWriter writer = new CSVWriter(w, ',','\u0000');
      for(int i=0;i<list.size();i++){
      System.out.println("list items"+list.get(i));
      String[] entries = list.get(i).split(",");
      writer.writeNext(entries);
      //System.out.println("list items : "+list.get(i));
      }
      writer.close();
      } catch (IOException e) {
      e.printStackTrace();
      }

      }
      -----------------------------------------------

      say the filetoberead.CSV contains following data,
      -----------------------------------------------
      0,22012013,E,E,ASG,,O-0000,O,0000,100
      1,111211,LI,0,TABO,B,M002500003593,,,К /БЭ60072715/,КАРТЕНБАЙ
      2,07,Balance Free,3
      1,383708,LI,0,BDSC,B,НЭ63041374,,,Т /НЭ63041374/,ОТГОНБААТАР
      2,07,Balance Free,161
      -----------------------------------------------

      It reads and writes the numbers and english characters correct. All cirillic characters it prints "?" as follows,
      -----------------------------------------------
      0,22012013,E,E,ASG,,O-0000,O,0000,100
      1,111211,LI,0,TABO,B,M002500003593,,,? /??60072715/,?????????
      2,07,Balance Free,3
      1,383708,LI,0,BDSC,B,??63041374,,,? /??63041374/,???????????
      2,07,Balance Free,161

      -----------------------------------------------

      can somone please help me to resolve this problem?

      Regards !
      Sameera