我正在使用 Bamini 字体在 JTable 中显示泰米尔语字体。它工作正常并显示泰米尔语字体。但是当我点击打印按钮时,它应该生成 HTML 格式的输出。但是如果我正在使用,
StringBuffer out = new StringBuffer();
out.append("<html><body>");
out.append(jTable1.getValueAt(0, 0));
out.append("காஷ்மீரில்");
out.append("</body></html>");
try {
Writer out1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("F:/hello.html"), "UTF-8"));
out1.write(out.toString());
out1.close();
} catch (IOException ex) {
Logger.getLogger(tabletest.class.getName()).log(Level.SEVERE, null, ex);
}
意味着它只显示一些不需要的垃圾字符,而不是泰米尔语字符。我怎样才能做到这一点?我的 HTML 文件的输出是,
此处காஷ்மீரில்是从其他网站复制的。它向我展示了垃圾字符。 JTable 的内容显示其实际的英文字符而不是转换字符。
最佳答案
现代 HTML 文件的基本结构如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Some Title</title>
</head>
<body>
Some contents
</body>
</html>
因此,您的代码应更正为:
StringBuffer out = new StringBuffer();
out.append("<!DOCTYPE html><html><head><meta charset=\"utf-8\" /><title>Some Title</title></head><body>");
out.append(jTable1.getValueAt(0, 0));
out.append("காஷ்மீரில்");
out.append("</body></html>");
关于java - 如何在 JTable 中显示泰米尔字体以生成 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27616123/