Question

I face a problem in file writing. When I write Bangla and English in file using UTF-8 format, the file contains exactly that what I write. But the problem is when I am going to use this file as a .srt file to show subtitle of a video in a media player

The mediaplayer can not show the bangla subtitle , instead of bangla word the media player show some english and some symbol....

But when I copy the contents of my file (in which I write) to other file , then using the other file, the media player can show exactly that what I write in file such as bangla, english .

My question is Why the 1st file can not do the same thing as the 2nd file do. And how can I remove this problem in code that I can use the 1st file.

BufferedWriter out = new BufferedWriter(
       new OutputStreamWriter(
                  new FileOutputStream(file), "UTF8"));
      int size=1;
      for(Tableclass variable:tablevector)
      {
            out.write(String.valueOf(size));
            out.newLine();
            out.write(variable.Starttime);
            out.write(" --> ");
            out.write(variable.Endtime);
            out.newLine();
            out.write(variable.Text);
            out.newLine();
            out.newLine();
          // output.format("%d\n%s --> %s\n%s\n\n",size,variable.Starttime,variable.Endtime,variable.Text);

        size++;
      }
      out.close();
Was it helpful?

Solution

You can use UTF16 instead of UTF8, then the 1st file will work.

BufferedWriter out = new BufferedWriter(
   new OutputStreamWriter(
              new FileOutputStream(file), "UTF16"));
  int size=1;
  for(Tableclass variable:tablevector)
  {
        out.write(String.valueOf(size));
        out.newLine();
        out.write(variable.Starttime);
        out.write(" --> ");
        out.write(variable.Endtime);
        out.newLine();
        out.write(variable.Text);
        out.newLine();
        out.newLine();
      // output.format("%d\n%s --> %s\n%s\n\n",size,variable.Starttime,variable.Endtime,variable.Text);

    size++;

  }
  out.close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top