Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将缅甸文本写入CSV文件_Java_Android - Fatal编程技术网

Java 如何将缅甸文本写入CSV文件

Java 如何将缅甸文本写入CSV文件,java,android,Java,Android,我想将缅甸文写入.csv文件。将缅甸文本写入.csv文件后,我使用MS Office打开该文件,但它不显示缅甸文本。 我的电脑中设置了缅甸字体。 下面是我的代码: OutputStreamWriter char_output = new OutputStreamWriter(new FileOutputStream(CSV.getAbsolutePath().toString()), Charset.forName("UTF-8").newEncoder()); char_outpu

我想将缅甸文写入
.csv
文件。将缅甸文本写入
.csv
文件后,我使用
MS Office
打开该文件,但它不显示缅甸文本。 我的电脑中设置了缅甸字体。 下面是我的代码:

OutputStreamWriter char_output = new OutputStreamWriter(new     

FileOutputStream(CSV.getAbsolutePath().toString()),
Charset.forName("UTF-8").newEncoder());
char_output.write(message + str);
char_output.write("\n");
for (int i = 0; i < pList.size(); i++)
{
    StringBuilder sb = new StringBuilder();
    sb.append(pList.get(i).getOrderNumber()).append(",").append(pList.get(i).getProductName()).append(",");
    sb.append(pList.get(i).getProductDiscription()).append(",").append(pList.get(i).getWeightKg()).append(",");
    sb.append(pList.get(i).getWeightViss()).append(",").append(pList.get(i).getQty()).append(",");
    sb.append(pList.get(i).getDate()).append("\n");
    char_output.write(sb.toString())`FileOutputStream(CSV.getAbsolutePath().toString() ),
}
char_output.close();
OutputStreamWriter char\u output=新的OutputStreamWriter(新的
FileOutputStream(CSV.getAbsolutePath().toString()),
字符集.forName(“UTF-8”).newEncoder();
字符输出。写入(消息+str);
字符输出。写入(“\n”);
对于(int i=0;i
许多人会说,使用CSV库

不使用
Charset.forName(“UTF-8”).newEncoder()
,只需使用
“UTF-8”
,但没有错

使用“\r\n”代替Windows下的“\n”可能更方便。(
System.getProperty(“file.encoding”)
将使用Android的“\n”。)

您需要处理逗号和引号。如果字符串值包含逗号,则应使用双引号。每一个内在的双引号都是自我转义的,即加倍

使用分号代替逗号。更好的是使用制表符
“\t”

要检测UTF-8,可以在文件开头写入BOM字符。这是一个零宽度的空间。BOM=字节顺序标记,参考UTF-16LE和UTF-16BE(反向字节对)

文件的结尾可能是“.csv”,但您也可以撒谎,并给它一个结尾“.xls”,让Excel通过双击打开它

sb.append("\uFEFF"); // Add a BOM at the begin of file.